change method addPlace
start TournamentTest implementation
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@DisplayName("TournamentTest")
|
||||
public class TournamentTest {
|
||||
|
||||
@Nested
|
||||
@DisplayName("KOMode")
|
||||
public class KOMode {
|
||||
private Tournament tournament;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
try {
|
||||
tournament = new Tournament("Name", Tournament.Type.KO);
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test invalid instance")
|
||||
void makeInvalidInstance() {
|
||||
assertThrows(InvalidNameException.class,() -> new Tournament(".", Tournament.Type.KO));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Save Participant")
|
||||
void saveParticipantTest() {
|
||||
//Checks if one Participant gets added
|
||||
Participant participantOne = Mockito.mock(Player.class);
|
||||
when(participantOne.equals(any(Participant.class))).thenReturn(false);
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Remove Participant")
|
||||
void removeParticipantTest() {
|
||||
Participant participant = Mockito.mock(Player.class);
|
||||
|
||||
//Checks if Error is thrown if Participant not in list
|
||||
assertThrows(Tournament.ParticipantNotExistsException.class,() -> tournament.removeParticipant(participant));
|
||||
|
||||
//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) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user