Skip to content

Commit

Permalink
Merge pull request #225 from sopra-fs24-group-09/M4_Test
Browse files Browse the repository at this point in the history
Edited test for ending game
  • Loading branch information
zihanltesla authored May 19, 2024
2 parents d7301c5 + a88bd3b commit d2f43d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit d2f43d7

Please sign in to comment.