use of com.faforever.server.entity.Division in project faf-java-server by FAForever.
the class DivisionServiceTest method testGetCurrentPlayerDivision.
@TestWith({ "1, 0.0f, 1", "1, 1.0f, 1", "1, 10.0f, 1", "1, 10.1f, 2", "1, 30.0f, 2", "2, 10.0f, 4", "2, 99.9f, 6", "3, 999.0f, 9" })
public void testGetCurrentPlayerDivision(int league, float score, int expectedDivisionId) throws Exception {
PlayerDivisionInfo info = new PlayerDivisionInfo();
info.setPlayer(player1);
info.setLeague(league);
info.setScore(score);
when(playerDivisionInfoRepository.findByPlayerAndSeason(player1, serverProperties.getLadder1v1().getSeason())).thenReturn(info);
Division result = instance.getCurrentPlayerDivision(player1).get();
assertEquals(result.getId(), expectedDivisionId);
}
use of com.faforever.server.entity.Division in project faf-java-server by FAForever.
the class DivisionService method getCurrentPlayerDivision.
public Optional<Division> getCurrentPlayerDivision(Player player) {
int season = properties.getLadder1v1().getSeason();
PlayerDivisionInfo info = playerDivisionInfoRepository.findByPlayerAndSeason(player, season);
if (info == null) {
return Optional.empty();
}
return Optional.of(divisions.stream().filter(division -> Objects.equals(division.getLeague(), info.getLeague())).filter(division -> info.getScore() <= division.getThreshold()).findFirst().orElseThrow(() -> new IllegalStateException(MessageFormat.format("Could not determine division for PlayerDivisionInfo {0}", info))));
}
use of com.faforever.server.entity.Division in project faf-java-server by FAForever.
the class DivisionServiceTest method setUp.
@Before
public void setUp() throws Exception {
serverProperties = new ServerProperties();
serverProperties.getLadder1v1().setSeason(1);
info1 = new PlayerDivisionInfo();
info1.setPlayer(player1);
info1.setSeason(serverProperties.getLadder1v1().getSeason());
info2 = new PlayerDivisionInfo();
info2.setPlayer(player2);
info2.setSeason(serverProperties.getLadder1v1().getSeason());
Division[] divisions = new Division[] { createDivision(1, "League 1 - Division A", 1, 10), createDivision(2, "League 1 - Division B", 1, 30), createDivision(3, "League 1 - Division C", 1, 50), createDivision(4, "League 2 - Division D", 2, 20), createDivision(5, "League 2 - Division E", 2, 60), createDivision(6, "League 2 - Division F", 2, 100), createDivision(7, "League 3 - Division G", 3, 100), createDivision(8, "League 3 - Division H", 3, 200), createDivision(9, "League 3 - Division I", 3, 9999) };
when(divisionRepository.findAllByOrderByLeagueAscThresholdAsc()).thenReturn(Arrays.asList(divisions));
instance = new DivisionService(serverProperties, divisionRepository, playerDivisionInfoRepository);
instance.init();
}
Aggregations