Test class #42

Merged
fassband merged 6 commits from testClass into main 2022-05-13 15:16:05 +02:00
3 changed files with 74 additions and 9 deletions
Showing only changes of commit 40cfd69436 - Show all commits

View File

@ -12,6 +12,7 @@ import javafx.scene.text.Font;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
public class Factory { public class Factory {
private TournamentDecorator tournamentDecorator; private TournamentDecorator tournamentDecorator;

View File

@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;

View File

@ -9,6 +9,7 @@ import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@DisplayName("TournamentTest") @DisplayName("TournamentTest")
@ -44,6 +45,8 @@ 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);
assertEquals(0, tournament.getParticipants().size());
tournament.saveParticipant(participantOne); tournament.saveParticipant(participantOne);
assertEquals(1, tournament.getParticipants().size()); assertEquals(1, tournament.getParticipants().size());
@ -78,8 +81,68 @@ public class TournamentTest {
} }
} }
@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());
} }
} }
}