|
|
|
@ -9,6 +9,7 @@ import org.mockito.Mockito;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
@DisplayName("TournamentTest")
|
|
|
|
@ -35,7 +36,7 @@ public class TournamentTest {
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Test invalid instance")
|
|
|
|
|
void makeInvalidInstance() {
|
|
|
|
|
assertThrows(InvalidNameException.class,() -> new Tournament(".", Tournament.Type.KO));
|
|
|
|
|
assertThrows(InvalidNameException.class, () -> new Tournament(".", Tournament.Type.KO));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -44,18 +45,20 @@ public class TournamentTest {
|
|
|
|
|
//Checks if one Participant gets added
|
|
|
|
|
Participant participantOne = Mockito.mock(Player.class);
|
|
|
|
|
when(participantOne.equals(any(Participant.class))).thenReturn(false);
|
|
|
|
|
|
|
|
|
|
assertEquals(0, tournament.getParticipants().size());
|
|
|
|
|
tournament.saveParticipant(participantOne);
|
|
|
|
|
assertEquals(1,tournament.getParticipants().size());
|
|
|
|
|
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());
|
|
|
|
|
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());
|
|
|
|
|
assertEquals(2, tournament.getParticipants().size());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -65,21 +68,81 @@ public class TournamentTest {
|
|
|
|
|
Participant participant = Mockito.mock(Player.class);
|
|
|
|
|
|
|
|
|
|
//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());
|
|
|
|
|
assertEquals(1, tournament.getParticipants().size());
|
|
|
|
|
try {
|
|
|
|
|
tournament.removeParticipant(participant);
|
|
|
|
|
assertEquals(0,tournament.getParticipants().size());
|
|
|
|
|
assertEquals(0, tournament.getParticipants().size());
|
|
|
|
|
} catch (Tournament.ParticipantNotExistsException e) {
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Add Place")
|
|
|
|
|
void addPlaceTest() {
|
|
|
|
|
Place place = mock(Place.class);
|
|
|
|
|
when(place.equals(any(Place.class))).thenReturn(false).thenReturn(true);
|
|
|
|
|
|
|
|
|
|
assertEquals(0, tournament.getPlaces().size());
|
|
|
|
|
tournament.addPlace(place);
|
|
|
|
|
assertEquals(1, tournament.getPlaces().size());
|
|
|
|
|
tournament.addPlace(place);
|
|
|
|
|
assertEquals(2, tournament.getPlaces().size());
|
|
|
|
|
tournament.addPlace(place);
|
|
|
|
|
assertEquals(2, tournament.getPlaces().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Remove Place")
|
|
|
|
|
void removePlaceTest() {
|
|
|
|
|
Place place = mock(Place.class);
|
|
|
|
|
|
|
|
|
|
assertThrows(Tournament.PlaceNotExistsException.class, () -> tournament.removePlace(place));
|
|
|
|
|
|
|
|
|
|
tournament.addPlace(place);
|
|
|
|
|
assertEquals(1, tournament.getPlaces().size());
|
|
|
|
|
try {
|
|
|
|
|
tournament.removePlace(place);
|
|
|
|
|
assertEquals(0, tournament.getPlaces().size());
|
|
|
|
|
} catch (Tournament.PlaceNotExistsException e) {
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@DisplayName("Test gameschedule calculation")
|
|
|
|
|
void calcGameSchedule() {
|
|
|
|
|
Participant participant = mock(Player.class);
|
|
|
|
|
when(participant.equals(any(Participant.class))).thenReturn(false);
|
|
|
|
|
|
|
|
|
|
//Checks if invalid number of Participants throws error
|
|
|
|
|
assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule());
|
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
|
if (i % 4 == 0 && i > 0) {
|
|
|
|
|
try {
|
|
|
|
|
tournament.createGameSchedule();
|
|
|
|
|
assertEquals(2, tournament.getGameList().size());
|
|
|
|
|
tournament.saveParticipant(participant);
|
|
|
|
|
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
assertThrows(Tournament.NumberOfParticipantInvalidException.class, () -> tournament.createGameSchedule());
|
|
|
|
|
tournament.saveParticipant(participant);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
tournament.createGameSchedule();
|
|
|
|
|
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
|
|
|
|
fail();
|
|
|
|
|
}
|
|
|
|
|
assertEquals(3, tournament.getGameList().size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|