Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package hdm.mi.sthbackend.serviceTests;
import hdm.mi.sthbackend.exeptions.BracketAlreadyInitializedException;
import hdm.mi.sthbackend.exeptions.BracketRoundNotFoundException;
import hdm.mi.sthbackend.exeptions.InsufficientTeamsException;
import hdm.mi.sthbackend.exeptions.TournamentIdNotFoundException;
import hdm.mi.sthbackend.model.Match;
import hdm.mi.sthbackend.model.Tournament;
import hdm.mi.sthbackend.repository.ITournamentRepository;
import hdm.mi.sthbackend.service.TournamentService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
class DetermineWinnerTest {
Logger log = LogManager.getLogger(DetermineWinnerTest.class);
@Mock
ITournamentRepository tournamentRepository;
@InjectMocks
TournamentService service;
@Test
void determineWinner() throws Exception {
int bracketRound = 0;
List<String> teamsNames = new ArrayList<>();
teamsNames.add("dummyTeam 01");
teamsNames.add("dummyTeam 02");
teamsNames.add("dummyTeam 03");
teamsNames.add("dummyTeam 04");
teamsNames.add("dummyTeam 05");
teamsNames.add("dummyTeam 06");
Tournament tournament = service.createTournament(new Tournament("dummyTournament", teamsNames));
try {
service.createBracket(tournament.getTournamentId());
} catch (TournamentIdNotFoundException | InsufficientTeamsException | BracketAlreadyInitializedException e) {
log.debug(e.getMessage());
}
try {
service.fillBracketRandom(tournament.getTournamentId());
} catch (TournamentIdNotFoundException e) {
log.debug("Error while trying to fill bracket");
}
Match match = tournament.getBracket().get(0).getMatches().entrySet().stream().findFirst().orElseThrow(Exception::new).getValue();
match.getTeamScores().keySet().forEach(System.out::println);
}
}