Testing #54
|
@ -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());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
//Checks if a allready added Particpant does not get added
|
||||||
when(participantOne.equals(any(Participant.class))).thenReturn(true);
|
when(participantOne.equals(any(Participant.class))).thenReturn(true);
|
||||||
tournament.saveParticipant(participantTwo);
|
tournament.saveParticipant(participantTwo);
|
||||||
assertEquals(2, tournament.getParticipants().size());
|
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
|
//Checks if Error is thrown if Participant not in list
|
||||||
assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant));
|
assertThrows(Tournament.ParticipantNotExistsException.class, () -> tournament.removeParticipant(participant));
|
||||||
|
|
||||||
|
try {
|
||||||
//Checks if participant gets removed
|
//Checks if participant gets removed
|
||||||
tournament.saveParticipant(participant);
|
tournament.saveParticipant(participant);
|
||||||
assertEquals(1, tournament.getParticipants().size());
|
assertEquals(1, tournament.getParticipants().size());
|
||||||
try {
|
|
||||||
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());
|
||||||
|
try {
|
||||||
tournament.saveParticipant(participant);
|
tournament.saveParticipant(participant);
|
||||||
|
} catch (Person.InvalidPhoneNumberException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue