Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edited test for ending game #225

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public void endGame(Game game) {

System.out.println("Game ended");
if (roomRepository.findByRoomId(game.getRoomId()).isPresent()){
roomRepository.delete(roomRepository.findById(game.getRoomId()).get());
roomRepository.delete(roomRepository.findByRoomId(game.getRoomId()).get());
socketService.broadcastLobbyInfo();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ public void testStartGame_success() throws IOException {
game.setGameStatus(GameStatus.ingame);
game.setRoomPlayersList(Arrays.asList("player1", "player2", "player3"));
room.setRoomWordsList(Arrays.asList("word1", "word2", "word3"));
game.setRoomId("1");


User player1 = new User();
player1.setId("player1");
player1.setInRoomId("1");
User player2 = new User();
player2.setId("player2");
player2.setInRoomId("1");
User player3 = new User();
player3.setId("player3");
player3.setInRoomId("1");


Player p1 = new Player(player1);
Expand All @@ -190,7 +194,8 @@ public void testStartGame_success() throws IOException {
when(userRepository.findById("player1")).thenReturn(Optional.of(player1));
when(userRepository.findById("player2")).thenReturn(Optional.of(player2));
when(userRepository.findById("player3")).thenReturn(Optional.of(player3));
when(roomRepository.findById("1")).thenReturn(Optional.of(room));
when(roomRepository.findByRoomId("1")).thenReturn(Optional.of(room));
doNothing().when(gameRepository).delete(game);

// Execute the method under test
gameService.startGame(room);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -460,14 +462,18 @@ public void testStartGame_success() throws IOException {
Game game = new Game(room);
game.setGameStatus(GameStatus.ingame);
game.setRoomPlayersList(Arrays.asList("player1", "player2", "player3"));
game.setRoomId("1");


User player1 = new User();
player1.setId("player1");
player1.setInRoomId("1");
User player2 = new User();
player2.setId("player2");
player2.setInRoomId("1");
User player3 = new User();
player3.setId("player3");
player3.setInRoomId("1");


Player p1 = new Player(player1);
Expand All @@ -488,7 +494,8 @@ public void testStartGame_success() throws IOException {
when(userRepository.findById("player1")).thenReturn(Optional.of(player1));
when(userRepository.findById("player2")).thenReturn(Optional.of(player2));
when(userRepository.findById("player3")).thenReturn(Optional.of(player3));
when(roomRepository.findById("1")).thenReturn(Optional.of(room));
when(roomRepository.findByRoomId("1")).thenReturn(Optional.of(room));
doNothing().when(gameRepository).delete(game);

// Execute the method under test
gameService.startGame(room);
Expand Down
Loading