Search in sources :

Example 1 with PlayerAchievement

use of com.faforever.api.data.domain.PlayerAchievement in project faf-java-api by FAForever.

the class EventsServiceTest method incrementExisting.

/**
 * Tests whether an achievement is properly incremented if it already existed.
 */
@Test
public void incrementExisting() throws Exception {
    mockAchievement("111", AchievementType.INCREMENTAL, 10);
    when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID)).thenReturn(Optional.of(createPlayerAchievement(4, REVEALED)));
    instance.increment(PLAYER_ID, "111", 3);
    PlayerAchievement playerAchievement = captureSaveEvent();
    assertThat(playerAchievement.getCurrentSteps(), is(7));
    assertThat(playerAchievement.getState(), is(REVEALED));
}
Also used : PlayerAchievement(com.faforever.api.data.domain.PlayerAchievement) Test(org.junit.Test)

Example 2 with PlayerAchievement

use of com.faforever.api.data.domain.PlayerAchievement in project faf-java-api by FAForever.

the class EventsServiceTest method setStepsAtLeastFirstTime.

/**
 * Tests whether an achievement's steps are properly set to the specified value if it's being set for the first time.
 */
@Test
public void setStepsAtLeastFirstTime() throws Exception {
    mockAchievement("111", AchievementType.INCREMENTAL, 10);
    when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID)).thenReturn(Optional.empty());
    instance.setStepsAtLeast(PLAYER_ID, "111", 4);
    PlayerAchievement playerAchievement = captureSaveEvent();
    assertThat(playerAchievement.getCurrentSteps(), is(4));
    assertThat(playerAchievement.getState(), is(REVEALED));
}
Also used : PlayerAchievement(com.faforever.api.data.domain.PlayerAchievement) Test(org.junit.Test)

Example 3 with PlayerAchievement

use of com.faforever.api.data.domain.PlayerAchievement in project faf-java-api by FAForever.

the class EventsServiceTest method setStepsAtLeastExistingLessSteps.

/**
 * Tests whether an achievement's steps are not updated if the existing steps are higher than the new steps.
 */
@Test
public void setStepsAtLeastExistingLessSteps() throws Exception {
    mockAchievement("111", AchievementType.INCREMENTAL, 10);
    when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID)).thenReturn(Optional.of(createPlayerAchievement(5, REVEALED)));
    instance.setStepsAtLeast(PLAYER_ID, "111", 4);
    PlayerAchievement playerAchievement = captureSaveEvent();
    assertThat(playerAchievement.getCurrentSteps(), is(5));
    assertThat(playerAchievement.getState(), is(REVEALED));
}
Also used : PlayerAchievement(com.faforever.api.data.domain.PlayerAchievement) Test(org.junit.Test)

Example 4 with PlayerAchievement

use of com.faforever.api.data.domain.PlayerAchievement in project faf-java-api by FAForever.

the class EventsServiceTest method unlockFirstTime.

/**
 * Tests whether a PlayerAchievement is properly created and unlocked if it's being unlocked the first time.
 */
@Test
public void unlockFirstTime() throws Exception {
    mockAchievement("111", AchievementType.STANDARD, null);
    when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID)).thenReturn(Optional.empty());
    instance.unlock(PLAYER_ID, "111");
    PlayerAchievement playerAchievement = captureSaveEvent();
    assertThat(playerAchievement.getCurrentSteps(), is(CoreMatchers.nullValue()));
    assertThat(playerAchievement.getState(), is(UNLOCKED));
}
Also used : PlayerAchievement(com.faforever.api.data.domain.PlayerAchievement) Test(org.junit.Test)

Example 5 with PlayerAchievement

use of com.faforever.api.data.domain.PlayerAchievement in project faf-java-api by FAForever.

the class EventsServiceTest method incrementFirstTime.

/**
 * Tests whether an achievement is properly created and incremented if it's being incremented for the first time.
 */
@Test
public void incrementFirstTime() throws Exception {
    mockAchievement("111", AchievementType.INCREMENTAL, 10);
    when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID)).thenReturn(Optional.empty());
    instance.increment(PLAYER_ID, "111", 3);
    PlayerAchievement playerAchievement = captureSaveEvent();
    assertThat(playerAchievement.getCurrentSteps(), is(3));
    assertThat(playerAchievement.getState(), is(REVEALED));
}
Also used : PlayerAchievement(com.faforever.api.data.domain.PlayerAchievement) Test(org.junit.Test)

Aggregations

PlayerAchievement (com.faforever.api.data.domain.PlayerAchievement)9 Test (org.junit.Test)6 Achievement (com.faforever.api.data.domain.Achievement)2 ApiException (com.faforever.api.error.ApiException)2 Error (com.faforever.api.error.Error)2