sync TournamentTest with new changes

create GameTest
This commit is contained in:
Andrin Fassbind 2022-05-13 21:11:33 +02:00
parent c8eff00e33
commit 135ec7e8d5
2 changed files with 57 additions and 23 deletions

View File

@ -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());
}
}

View File

@ -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);
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());
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));
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
try {
//Checks if participant gets removed
tournament.saveParticipant(participant);
assertEquals(1, tournament.getParticipants().size());
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());
tournament.saveParticipant(participant);
try {
tournament.saveParticipant(participant);
} catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace();
}
}
}
try {