Skip to content

Commit

Permalink
Fix more Code Inspection Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
IDragonfire committed May 11, 2017
1 parent cea112f commit 7f489b7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void incrementFirstTime() throws Exception {

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

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(3));
assertThat(playerAchievement.getState(), is(REVEALED));
Expand All @@ -78,7 +78,7 @@ private void mockAchievement(String achievementId, AchievementType type, Integer
when(achievementRepository.getOne(achievementId)).thenReturn(achievement);
}

private PlayerAchievement catpureSaveEvent() {
private PlayerAchievement captureSaveEvent() {
ArgumentCaptor<PlayerAchievement> captor = ArgumentCaptor.forClass(PlayerAchievement.class);
verify(playerAchievementRepository).save(captor.capture());
return captor.getValue();
Expand All @@ -95,7 +95,7 @@ public void incrementExisting() throws Exception {

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

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(7));
assertThat(playerAchievement.getState(), is(REVEALED));
Expand Down Expand Up @@ -126,7 +126,7 @@ public void setStepsAtLeastFirstTime() throws Exception {

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

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(4));
assertThat(playerAchievement.getState(), is(REVEALED));
Expand All @@ -143,7 +143,7 @@ public void setStepsAtLeastExistingLessSteps() throws Exception {

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

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(5));
assertThat(playerAchievement.getState(), is(REVEALED));
Expand All @@ -160,7 +160,7 @@ public void setStepsAtLeastExistingMoreSteps() throws Exception {

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

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(6));
assertThat(playerAchievement.getState(), is(REVEALED));
Expand All @@ -177,7 +177,7 @@ public void unlockFirstTime() throws Exception {

instance.unlock(PLAYER_ID, "111");

PlayerAchievement playerAchievement = catpureSaveEvent();
PlayerAchievement playerAchievement = captureSaveEvent();

assertThat(playerAchievement.getCurrentSteps(), is(CoreMatchers.nullValue()));
assertThat(playerAchievement.getState(), is(UNLOCKED));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.faforever.integration.factories.SessionFactory;
import com.faforever.integration.factories.SessionFactory.Session;
import com.faforever.integration.utils.MockMvcHelper;
import lombok.SneakyThrows;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import org.junit.After;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class JsonApiClanIntegrationTest {

private TestDatabase database;

private ObjectMapper objectMapper;
private final ObjectMapper objectMapper;

public JsonApiClanIntegrationTest() {
objectMapper = new ObjectMapper();
Expand Down Expand Up @@ -169,7 +170,8 @@ public void getFilteredPlayerForClanInvite() throws Exception {
.andExpect(jsonPath("$.data[1].attributes.login", is("Dragonfire")));
}

private String generateTransferLeadershipContent(int clanId, int newLeaderId) throws Exception {
@SneakyThrows
private String generateTransferLeadershipContent(int clanId, int newLeaderId) {
ObjectNode node = this.objectMapper.createObjectNode();
ObjectNode data = this.objectMapper.createObjectNode();
ObjectNode relationships = this.objectMapper.createObjectNode();
Expand Down
34 changes: 17 additions & 17 deletions src/test/java/com/faforever/api/map/MapServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public class MapServiceTest {
public void setUp() {
instance = new MapService(fafApiProperties, mapRepository, contentService);
mapProperties = new Map()
.setTargetDirectory(finalDirectory.getRoot().toPath())
.setDirectoryPreviewPathLarge(finalDirectory.getRoot().toPath().resolve("large"))
.setDirectoryPreviewPathSmall(finalDirectory.getRoot().toPath().resolve("small"));
.setTargetDirectory(finalDirectory.getRoot().toPath())
.setDirectoryPreviewPathLarge(finalDirectory.getRoot().toPath().resolve("large"))
.setDirectoryPreviewPathSmall(finalDirectory.getRoot().toPath().resolve("small"));
when(fafApiProperties.getMap()).thenReturn(mapProperties);
when(contentService.createTempDir()).thenReturn(temporaryDirectory.getRoot().toPath());
}
Expand All @@ -86,7 +86,7 @@ public void shutDown() {
@Test
public void zipFilenamealreadyExists() throws IOException {
Path clashedMap = finalDirectory.getRoot().toPath().resolve("sludge_test.v0001.zip");
clashedMap.toFile().createNewFile();
assertTrue(clashedMap.toFile().createNewFile());
String zipFilename = "scmp_037.zip";
when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.empty());
try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
Expand Down Expand Up @@ -147,8 +147,8 @@ public void versionExistsAlready() throws IOException {
me.setId(1);

com.faforever.api.data.domain.Map map = new com.faforever.api.data.domain.Map()
.setAuthor(me)
.setVersions(Collections.singletonList(new MapVersion().setVersion(1)));
.setAuthor(me)
.setVersions(Collections.singletonList(new MapVersion().setVersion(1)));

when(mapRepository.findOneByDisplayName(any())).thenReturn(Optional.of(map));
try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
Expand Down Expand Up @@ -196,12 +196,12 @@ public void invalidScenario() throws IOException {
try (InputStream inputStream = loadMapResourceAsStream(zipFilename)) {
byte[] mapData = ByteStreams.toByteArray(inputStream);
expectedException.expect(ApiExceptionWithMultipleCodes.apiExceptionWithCode(
ErrorCode.MAP_NAME_MISSING,
ErrorCode.MAP_DESCRIPTION_MISSING,
ErrorCode.MAP_FIRST_TEAM_FFA,
ErrorCode.MAP_TYPE_MISSING,
ErrorCode.MAP_SIZE_MISSING,
ErrorCode.MAP_VERSION_MISSING));
ErrorCode.MAP_NAME_MISSING,
ErrorCode.MAP_DESCRIPTION_MISSING,
ErrorCode.MAP_FIRST_TEAM_FFA,
ErrorCode.MAP_TYPE_MISSING,
ErrorCode.MAP_SIZE_MISSING,
ErrorCode.MAP_VERSION_MISSING));
instance.uploadMap(mapData, zipFilename, author, true);
}
verify(mapRepository, never()).save(any(com.faforever.api.data.domain.Map.class));
Expand Down Expand Up @@ -253,13 +253,13 @@ public void positiveUploadTest() throws IOException {

Path generatedFiles = finalDirectory.getRoot().toPath().resolve("generated_files");
try (ZipInputStream inputStreamOfExpectedFile = new ZipInputStream(
new BufferedInputStream(new FileInputStream(generatedFile.toFile())))) {
new BufferedInputStream(new FileInputStream(generatedFile.toFile())))) {
Unzipper.from(inputStreamOfExpectedFile).to(generatedFiles).unzip();
}

Path expectedFiles = finalDirectory.getRoot().toPath().resolve("expected_files");
try (ZipInputStream inputStreamOfExpectedFile = new ZipInputStream(new BufferedInputStream(
loadMapResourceAsStream("sludge_test.v0001.zip")))) {
loadMapResourceAsStream("sludge_test.v0001.zip")))) {
Unzipper.from(inputStreamOfExpectedFile).to(expectedFiles).unzip();
}

Expand All @@ -271,9 +271,9 @@ public void positiveUploadTest() throws IOException {
try (Stream<Path> fileStream = Files.list(expectedFiles)) {
Path finalGeneratedFile = generatedFiles.resolve("sludge_test.v0001");
fileStream.forEach(expectedFile ->
FileAssert.assertEquals("Difference in " + expectedFile.getFileName().toString(),
expectedFile.toFile(),
finalGeneratedFile.resolve(expectedFile.getFileName().toString()).toFile())
FileAssert.assertEquals("Difference in " + expectedFile.getFileName().toString(),
expectedFile.toFile(),
finalGeneratedFile.resolve(expectedFile.getFileName().toString()).toFile())
);

assertTrue(Files.exists(mapProperties.getDirectoryPreviewPathLarge().resolve("sludge_test.v0001.png")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class SessionFactory {
private static final String OAUTH_CLIENT_ID = "1234";
private static final String OAUTH_SECRET = "secret";

private static ObjectMapper objectMapper = new ObjectMapper();
private static ShaPasswordEncoder shaPasswordEncoder = new ShaPasswordEncoder(256);
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ShaPasswordEncoder shaPasswordEncoder = new ShaPasswordEncoder(256);

@SneakyThrows
public static Session createUserAndGetAccessToken(TestDatabase database,
MockMvc mvc) {
return createUserAndGetAccessToken("JUnitOnDragonFire", "myCoolPassword",
database, mvc);
database, mvc);
}

@SneakyThrows
Expand All @@ -41,34 +41,34 @@ public static Session createUserAndGetAccessToken(String login,
TestDatabase database,
MockMvc mvc) {
OAuthClient client = new OAuthClient()
.setId(OAUTH_CLIENT_ID)
.setName("test")
.setClientSecret(OAUTH_SECRET)
.setRedirectUris("test")
.setDefaultRedirectUri("test")
.setDefaultScope("test")
.setClientType(ClientType.PUBLIC);
.setId(OAUTH_CLIENT_ID)
.setName("test")
.setClientSecret(OAUTH_SECRET)
.setRedirectUris("test")
.setDefaultRedirectUri("test")
.setDefaultScope("test")
.setClientType(ClientType.PUBLIC);
database.getOAuthClientRepository().save(client);

long userCounter = database.getUserRepository().count();
User user = (User) new User()
.setPassword(shaPasswordEncoder.encodePassword(password, null))
.setLogin(login)
.setEmail(login + "@example.com");
.setPassword(shaPasswordEncoder.encodePassword(password, null))
.setLogin(login)
.setEmail(login + "@example.com");
database.getUserRepository().save(user);
assertEquals((userCounter + 1), database.getUserRepository().count());

Player player = database.getPlayerRepository().findOne(user.getId());
Assert.assertNotNull(player);

String authorization = "Basic "
+ new String(Base64Utils.encode((OAUTH_CLIENT_ID + ":" + OAUTH_SECRET).getBytes()));
+ new String(Base64Utils.encode((OAUTH_CLIENT_ID + ":" + OAUTH_SECRET).getBytes()));
ResultActions auth = MockMvcHelper.of(mvc).perform(
post("/oauth/token")
.header("Authorization", authorization)
.param("username", login)
.param("password", password)
.param("grant_type", "password"));
post("/oauth/token")
.header("Authorization", authorization)
.param("username", login)
.param("password", password)
.param("grant_type", "password"));
auth.andExpect(status().isOk());
JsonNode node = objectMapper.readTree(auth.andReturn().getResponse().getContentAsString());
String token = node.get("access_token").asText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static MockMvcHelperObject of(MockMvc mvc) {


public static class MockMvcHelperObject {
private MockMvc mvc;
private final MockMvc mvc;
@Setter
private Session session;

Expand Down

0 comments on commit 7f489b7

Please sign in to comment.