sync TournamentTest with new changes

create GameTest
This commit is contained in:
Andrin Fassbind 2022-05-13 21:11:33 +02:00
parent c8eff00e33
commit 135ec7e8d5
2 changed files with 57 additions and 23 deletions

View File

@ -1,13 +1,41 @@
package ch.zhaw.projekt2.turnierverwaltung; package ch.zhaw.projekt2.turnierverwaltung;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
public class GameTest { public class GameTest {
private Game game; private Game game;
@BeforeEach @Test
void setup() { @DisplayName("TestWinner")
void testWinnerFunction() {
Participant one = Mockito.mock(Player.class);
Participant two = Mockito.mock(Player.class);
game = new Game(one,two);
game.setPoints1(1);
Assertions.assertEquals(one,game.getWinner());
game.setPoints2(2);
Assertions.assertEquals(two,game.getWinner());
}
@Test
@DisplayName("Test refresh Participant")
void refreshTest() {
Participant one = Mockito.mock(Player.class);
Participant two = Mockito.mock(Player.class);
Game game1 = new Game(one,two);
Game game2 = new Game(one,two);
game = new Game(game1,game2);
game1.setPoints1(2);
game2.setPoints2(2);
Assertions.assertNull(game.getParticipant1());
Assertions.assertNull(game.getParticipant2());
game.refreshParticipants();
Assertions.assertEquals(one,game.getParticipant1());
Assertions.assertEquals(two,game.getParticipant2());
} }
} }

View File

@ -44,20 +44,21 @@ public class TournamentTest {
//Checks if one Participant gets added //Checks if one Participant gets added
Participant participantOne = Mockito.mock(Player.class); Participant participantOne = Mockito.mock(Player.class);
when(participantOne.equals(any(Participant.class))).thenReturn(false); when(participantOne.equals(any(Participant.class))).thenReturn(false);
try {
assertEquals(0, tournament.getParticipants().size()); assertEquals(0, tournament.getParticipants().size());
tournament.saveParticipant(participantOne); tournament.saveParticipant(participantOne);
assertEquals(1, tournament.getParticipants().size()); assertEquals(1, tournament.getParticipants().size());
//Checks if a second Participant gets added
//Checks if a second Participant gets added Participant participantTwo = Mockito.mock(Player.class);
Participant participantTwo = Mockito.mock(Player.class); tournament.saveParticipant(participantTwo);
tournament.saveParticipant(participantTwo); assertEquals(2, tournament.getParticipants().size());
assertEquals(2, tournament.getParticipants().size()); //Checks if a allready added Particpant does not get added
when(participantOne.equals(any(Participant.class))).thenReturn(true);
//Checks if a allready added Particpant does not get added tournament.saveParticipant(participantTwo);
when(participantOne.equals(any(Participant.class))).thenReturn(true); assertEquals(2, tournament.getParticipants().size());
tournament.saveParticipant(participantTwo); } catch (Person.InvalidPhoneNumberException e) {
assertEquals(2, tournament.getParticipants().size()); fail();
}
} }
@ -69,13 +70,13 @@ public class TournamentTest {
//Checks if Error is thrown if Participant not in list //Checks if Error is thrown if Participant not in list
assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant)); assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant));
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
try { try {
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
tournament.removeParticipant(participant); tournament.removeParticipant(participant);
assertEquals(0, tournament.getParticipants().size()); assertEquals(0, tournament.getParticipants().size());
} catch (Tournament.ParticipantNotExistsException e) { } catch (Tournament.ParticipantNotExistsException | Person.InvalidPhoneNumberException e) {
fail(); fail();
} }
} }
@ -126,13 +127,18 @@ public class TournamentTest {
tournament.createGameSchedule(); tournament.createGameSchedule();
assertEquals(2, tournament.getGameList().size()); assertEquals(2, tournament.getGameList().size());
tournament.saveParticipant(participant); tournament.saveParticipant(participant);
} catch (Tournament.NumberOfParticipantInvalidException e) { } catch (Tournament.NumberOfParticipantInvalidException | Person.InvalidPhoneNumberException e) {
fail(); fail();
} }
} else { } else {
assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule()); assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule());
tournament.saveParticipant(participant); try {
tournament.saveParticipant(participant);
} catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace();
}
} }
} }
try { try {