Skip to content

Commit

Permalink
Fix Deprecated API usage and correct test formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
IDragonfire committed May 11, 2017
1 parent 404185d commit cea112f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Optional;

Expand Down Expand Up @@ -59,7 +59,7 @@ public void setUp() throws Exception {
public void incrementFirstTime() throws Exception {
mockAchievement("111", AchievementType.INCREMENTAL, 10);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.empty());
.thenReturn(Optional.empty());

instance.increment(PLAYER_ID, "111", 3);

Expand Down Expand Up @@ -91,7 +91,7 @@ private PlayerAchievement catpureSaveEvent() {
public void incrementExisting() throws Exception {
mockAchievement("111", AchievementType.INCREMENTAL, 10);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.of(createPlayerAchievement(4, REVEALED)));
.thenReturn(Optional.of(createPlayerAchievement(4, REVEALED)));

instance.increment(PLAYER_ID, "111", 3);

Expand Down Expand Up @@ -122,7 +122,7 @@ public void incrementNonIncremental() throws Exception {
public void setStepsAtLeastFirstTime() throws Exception {
mockAchievement("111", AchievementType.INCREMENTAL, 10);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.empty());
.thenReturn(Optional.empty());

instance.setStepsAtLeast(PLAYER_ID, "111", 4);

Expand All @@ -139,7 +139,7 @@ public void setStepsAtLeastFirstTime() throws Exception {
public void setStepsAtLeastExistingLessSteps() throws Exception {
mockAchievement("111", AchievementType.INCREMENTAL, 10);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.of(createPlayerAchievement(5, REVEALED)));
.thenReturn(Optional.of(createPlayerAchievement(5, REVEALED)));

instance.setStepsAtLeast(PLAYER_ID, "111", 4);

Expand All @@ -156,7 +156,7 @@ public void setStepsAtLeastExistingLessSteps() throws Exception {
public void setStepsAtLeastExistingMoreSteps() throws Exception {
mockAchievement("111", AchievementType.INCREMENTAL, 10);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.of(createPlayerAchievement(5, REVEALED)));
.thenReturn(Optional.of(createPlayerAchievement(5, REVEALED)));

instance.setStepsAtLeast(PLAYER_ID, "111", 6);

Expand All @@ -173,7 +173,7 @@ public void setStepsAtLeastExistingMoreSteps() throws Exception {
public void unlockFirstTime() throws Exception {
mockAchievement("111", AchievementType.STANDARD, null);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.empty());
.thenReturn(Optional.empty());

instance.unlock(PLAYER_ID, "111");

Expand All @@ -190,7 +190,7 @@ public void unlockFirstTime() throws Exception {
public void unlockSecondTime() throws Exception {
mockAchievement("111", AchievementType.STANDARD, null);
when(playerAchievementRepository.findOneByAchievementIdAndPlayerId("111", PLAYER_ID))
.thenReturn(Optional.of(createPlayerAchievement(null, UNLOCKED)));
.thenReturn(Optional.of(createPlayerAchievement(null, UNLOCKED)));

instance.unlock(PLAYER_ID, "111");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
Expand All @@ -33,19 +33,19 @@ public void setUp() throws Exception {
@Test
public void update() throws Exception {
AchievementUpdateRequest[] updateRequests = new AchievementUpdateRequest[]{
new AchievementUpdateRequest(1, "111", Operation.INCREMENT, 7),
new AchievementUpdateRequest(1, "222", Operation.INCREMENT, 19),
new AchievementUpdateRequest(1, "333", Operation.SET_STEPS_AT_LEAST, 9),
new AchievementUpdateRequest(1, "444", Operation.SET_STEPS_AT_LEAST, 13),
new AchievementUpdateRequest(1, "555", Operation.UNLOCK, 11),
new AchievementUpdateRequest(1, "666", Operation.UNLOCK, 17),
new AchievementUpdateRequest(1, "111", Operation.INCREMENT, 7),
new AchievementUpdateRequest(1, "222", Operation.INCREMENT, 19),
new AchievementUpdateRequest(1, "333", Operation.SET_STEPS_AT_LEAST, 9),
new AchievementUpdateRequest(1, "444", Operation.SET_STEPS_AT_LEAST, 13),
new AchievementUpdateRequest(1, "555", Operation.UNLOCK, 11),
new AchievementUpdateRequest(1, "666", Operation.UNLOCK, 17),
};
when(achievementService.increment(anyInt(), any(), anyInt())).thenAnswer(invocation ->
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
when(achievementService.setStepsAtLeast(anyInt(), any(), anyInt())).thenAnswer(invocation ->
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED, invocation.getArgument(2)));
when(achievementService.unlock(anyInt(), any())).thenAnswer(invocation ->
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED));
new UpdatedAchievementResponse(invocation.getArgument(1), true, AchievementState.UNLOCKED));

JsonApiDocument result = instance.update(updateRequests);

Expand Down
50 changes: 25 additions & 25 deletions src/test/java/com/faforever/api/clan/ClanServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.jwt.Jwt;

import java.io.IOException;
Expand Down Expand Up @@ -177,10 +177,10 @@ public void generatePlayerInvitationTokenFromNonLeader() throws IOException {
leader.setId(3);

Clan clan = new Clan()
.setId(1)
.setTag("123")
.setName("abc")
.setLeader(leader);
.setId(1)
.setTag("123")
.setName("abc")
.setLeader(leader);

when(clanRepository.findOne(clan.getId())).thenReturn(clan);

Expand All @@ -199,10 +199,10 @@ public void generatePlayerInvitationTokenInvalidPlayer() throws IOException {
requester.setId(1);

Clan clan = new Clan()
.setId(1)
.setTag("123")
.setName("abc")
.setLeader(requester);
.setId(1)
.setTag("123")
.setName("abc")
.setLeader(requester);

when(clanRepository.findOne(clan.getId())).thenReturn(clan);

Expand All @@ -224,9 +224,9 @@ public void generatePlayerInvitationToken() throws IOException {
newMember.setId(2);

Clan clan = new Clan()
.setId(1)
.setTag("123")
.setName("abc");
.setId(1)
.setTag("123")
.setName("abc");
clan.setLeader(requester);

FafApiProperties props = new FafApiProperties();
Expand All @@ -239,8 +239,8 @@ public void generatePlayerInvitationToken() throws IOException {
ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class);
verify(jwtService, Mockito.times(1)).sign(captor.capture());
assertThat("expire",
Long.parseLong(captor.getValue().get("expire").toString()),
greaterThan(System.currentTimeMillis()));
Long.parseLong(captor.getValue().get("expire").toString()),
greaterThan(System.currentTimeMillis()));
assertEquals(newMember.getId(), captor.getValue().get("newMemberId"));
assertEquals(clan.getId(), ((Map) captor.getValue().get("clan")).get("id"));
assertEquals(clan.getTag(), ((Map) captor.getValue().get("clan")).get("tag"));
Expand All @@ -254,7 +254,7 @@ public void acceptPlayerInvitationTokenExpire() throws IOException {
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s}", expire));
String.format("{\"expire\":%s}", expire));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);

try {
Expand All @@ -274,7 +274,7 @@ public void acceptPlayerInvitationTokenInvalidClan() throws IOException {
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s,\"clan\":{\"id\":42}}", expire));
String.format("{\"expire\":%s,\"clan\":{\"id\":42}}", expire));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);

try {
Expand All @@ -296,8 +296,8 @@ public void acceptPlayerInvitationTokenInvalidPlayer() throws IOException {
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s,\"newMemberId\":2,\"clan\":{\"id\":%s}}",
expire, clan.getId()));
String.format("{\"expire\":%s,\"newMemberId\":2,\"clan\":{\"id\":%s}}",
expire, clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findOne(clan.getId())).thenReturn(clan);

Expand Down Expand Up @@ -326,8 +326,8 @@ public void acceptPlayerInvitationTokenWrongPlayer() throws IOException {
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findOne(clan.getId())).thenReturn(clan);
when(playerRepository.findOne(newMember.getId())).thenReturn(newMember);
Expand All @@ -351,14 +351,14 @@ public void acceptPlayerInvitationTokenPlayerIAlreadyInAClan() throws IOExceptio
Player newMember = new Player();
newMember.setId(2);
newMember.setClanMemberships(
Collections.singletonList(new ClanMembership().setClan(clan).setPlayer(newMember)));
Collections.singletonList(new ClanMembership().setClan(clan).setPlayer(newMember)));

long expire = System.currentTimeMillis() + 1000 * 3;
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findOne(clan.getId())).thenReturn(clan);
when(playerRepository.findOne(newMember.getId())).thenReturn(newMember);
Expand All @@ -383,8 +383,8 @@ public void acceptPlayerInvitationToken() throws IOException {
Jwt jwtToken = Mockito.mock(Jwt.class);

when(jwtToken.getClaims()).thenReturn(
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
String.format("{\"expire\":%s,\"newMemberId\":%s,\"clan\":{\"id\":%s}}",
expire, newMember.getId(), clan.getId()));
when(jwtService.decodeAndVerify(any())).thenReturn(jwtToken);
when(clanRepository.findOne(clan.getId())).thenReturn(clan);
when(playerRepository.findOne(newMember.getId())).thenReturn(newMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -35,8 +35,8 @@ public void setUp() throws Exception {
@Test
public void getLadder1v1() throws Exception {
when(leaderboardService.getLadder1v1Leaderboard()).thenReturn(Arrays.asList(
new Ladder1v1LeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1).setWonGames((short) 270),
new Ladder1v1LeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2).setWonGames((short) 32)
new Ladder1v1LeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1).setWonGames((short) 270),
new Ladder1v1LeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2).setWonGames((short) 32)
));

CompletableFuture<JsonApiDocument> result = instance.getLadder1v1();
Expand Down Expand Up @@ -70,8 +70,8 @@ public void getLadder1v1() throws Exception {
@Test
public void getGlobal() throws Exception {
when(leaderboardService.getGlobalLeaderboard()).thenReturn(Arrays.asList(
new GlobalLeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1),
new GlobalLeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2)
new GlobalLeaderboardEntry().setId(14).setPlayerName("JUnit 14").setMean(1500f).setDeviation(51f).setNumGames((short) 514).setRank(1),
new GlobalLeaderboardEntry().setId(5).setPlayerName("JUnit 5").setMean(1400f).setDeviation(67f).setNumGames((short) 65).setRank(2)
));

CompletableFuture<JsonApiDocument> result = instance.getGlobal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationException;

Expand Down

0 comments on commit cea112f

Please sign in to comment.