Search in sources :

Example 1 with Division

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);
}
Also used : PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo) Division(com.faforever.server.entity.Division) TestWith(com.googlecode.zohhak.api.TestWith)

Example 2 with Division

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))));
}
Also used : Getter(lombok.Getter) Transactional(javax.transaction.Transactional) PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo) MessageFormat(java.text.MessageFormat) Player(com.faforever.server.entity.Player) Inject(javax.inject.Inject) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) Slf4j(lombok.extern.slf4j.Slf4j) ImmutableList(com.google.common.collect.ImmutableList) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) Division(com.faforever.server.entity.Division) NotNull(org.jetbrains.annotations.NotNull) PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo)

Example 3 with Division

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();
}
Also used : PlayerDivisionInfo(com.faforever.server.entity.PlayerDivisionInfo) ServerProperties(com.faforever.server.config.ServerProperties) Division(com.faforever.server.entity.Division) Before(org.junit.Before)

Aggregations

Division (com.faforever.server.entity.Division)3 PlayerDivisionInfo (com.faforever.server.entity.PlayerDivisionInfo)3 ServerProperties (com.faforever.server.config.ServerProperties)2 Player (com.faforever.server.entity.Player)1 ImmutableList (com.google.common.collect.ImmutableList)1 TestWith (com.googlecode.zohhak.api.TestWith)1 MessageFormat (java.text.MessageFormat)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 PostConstruct (javax.annotation.PostConstruct)1 Inject (javax.inject.Inject)1 Transactional (javax.transaction.Transactional)1 Getter (lombok.Getter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Before (org.junit.Before)1 Service (org.springframework.stereotype.Service)1