parent
c8eff00e33
commit
135ec7e8d5
|
@ -1,13 +1,41 @@
|
|||
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 {
|
||||
|
||||
private Game game;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
@Test
|
||||
@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());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,20 +44,21 @@ public class TournamentTest {
|
|||
//Checks if one Participant gets added
|
||||
Participant participantOne = Mockito.mock(Player.class);
|
||||
when(participantOne.equals(any(Participant.class))).thenReturn(false);
|
||||
|
||||
try {
|
||||
assertEquals(0, tournament.getParticipants().size());
|
||||
tournament.saveParticipant(participantOne);
|
||||
assertEquals(1, tournament.getParticipants().size());
|
||||
|
||||
//Checks if a second Participant gets added
|
||||
Participant participantTwo = Mockito.mock(Player.class);
|
||||
tournament.saveParticipant(participantTwo);
|
||||
assertEquals(2, tournament.getParticipants().size());
|
||||
|
||||
//Checks if a allready added Particpant does not get added
|
||||
when(participantOne.equals(any(Participant.class))).thenReturn(true);
|
||||
tournament.saveParticipant(participantTwo);
|
||||
assertEquals(2, tournament.getParticipants().size());
|
||||
} catch (Person.InvalidPhoneNumberException e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -69,13 +70,13 @@ public class TournamentTest {
|
|||
//Checks if Error is thrown if Participant not in list
|
||||
assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant));
|
||||
|
||||
try {
|
||||
//Checks if participant gets removed
|
||||
tournament.saveParticipant(participant);
|
||||
assertEquals(1, tournament.getParticipants().size());
|
||||
try {
|
||||
tournament.removeParticipant(participant);
|
||||
assertEquals(0, tournament.getParticipants().size());
|
||||
} catch (Tournament.ParticipantNotExistsException e) {
|
||||
} catch (Tournament.ParticipantNotExistsException | Person.InvalidPhoneNumberException e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
@ -126,13 +127,18 @@ public class TournamentTest {
|
|||
tournament.createGameSchedule();
|
||||
assertEquals(2, tournament.getGameList().size());
|
||||
tournament.saveParticipant(participant);
|
||||
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
||||
} catch (Tournament.NumberOfParticipantInvalidException | Person.InvalidPhoneNumberException e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule());
|
||||
try {
|
||||
tournament.saveParticipant(participant);
|
||||
} catch (Person.InvalidPhoneNumberException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue