From 64fc1b2b392dbd48ec773472098903b8e4c034c2 Mon Sep 17 00:00:00 2001 From: alexandrou Date: Wed, 4 Mar 2020 11:45:22 +0000 Subject: [PATCH] Spotless. --- build.gradle | 1 - .../web3j/console/account/AccountManager.java | 19 ++----- .../console/project/UnitTestCreator.java | 13 ++--- .../console/account/AccountManagerTest.java | 49 +++++++++++++------ 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index 15d99d8..b09f179 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,6 @@ apply { repositories { maven { url "https://dl.bintray.com/ethereum/maven/" } - } test { diff --git a/src/main/java/org/web3j/console/account/AccountManager.java b/src/main/java/org/web3j/console/account/AccountManager.java index 3c89ae7..ccc4713 100644 --- a/src/main/java/org/web3j/console/account/AccountManager.java +++ b/src/main/java/org/web3j/console/account/AccountManager.java @@ -18,7 +18,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import okhttp3.FormBody; -import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; @@ -40,7 +39,6 @@ public AccountManager(final CliConfig cliConfig, OkHttpClient client) { this.config = cliConfig; } - public static void main(final CliConfig config, final String[] args) { Scanner console = new Scanner(System.in); @@ -61,11 +59,9 @@ public void createAccount(String email) { try { Response sendRawResponse = executeClientCall(newAccountRequest); ResponseBody body; - if (sendRawResponse.code() == 200 - && (body = sendRawResponse.body()) != null) { + if (sendRawResponse.code() == 200 && (body = sendRawResponse.body()) != null) { String rawResponse = body.string(); - JsonObject responseJsonObj = - JsonParser.parseString(rawResponse).getAsJsonObject(); + JsonObject responseJsonObj = JsonParser.parseString(rawResponse).getAsJsonObject(); if (responseJsonObj.get("token") == null) { String tokenError = responseJsonObj.get("tokenError").getAsString(); @@ -80,7 +76,6 @@ public void createAccount(String email) { System.out.println("Account creation failed. Please try again later."); } - } catch (IOException e) { System.out.println("Could not connect to the server.\nReason:" + e.getMessage()); } @@ -93,19 +88,13 @@ protected final Response executeClientCall(Request newAccountRequest) throws IOE protected final RequestBody createRequestBody(String email) { - return new FormBody.Builder().add("email", email) - .build(); - - + return new FormBody.Builder().add("email", email).build(); } protected final Request createRequest(RequestBody accountBody) { return new Request.Builder() - .url( - String.format( - "%s/auth/realms/EpirusPortal/web3j-token/create", - CLOUD_URL)) + .url(String.format("%s/auth/realms/EpirusPortal/web3j-token/create", CLOUD_URL)) .post(accountBody) .build(); } diff --git a/src/main/java/org/web3j/console/project/UnitTestCreator.java b/src/main/java/org/web3j/console/project/UnitTestCreator.java index 390d824..149db68 100644 --- a/src/main/java/org/web3j/console/project/UnitTestCreator.java +++ b/src/main/java/org/web3j/console/project/UnitTestCreator.java @@ -12,18 +12,19 @@ */ package org.web3j.console.project; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import picocli.CommandLine; + import org.web3j.codegen.Console; import org.web3j.codegen.unit.gen.ClassProvider; import org.web3j.codegen.unit.gen.java.JavaClassGenerator; import org.web3j.codegen.unit.gen.kotlin.KotlinClassGenerator; import org.web3j.console.project.java.JavaTestCLIRunner; import org.web3j.console.project.kotlin.KotlinTestCLIRunner; -import picocli.CommandLine; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import static org.web3j.console.project.ProjectCreator.COMMAND_JAVA; import static org.web3j.utils.Collection.tail; diff --git a/src/test/java/org/web3j/console/account/AccountManagerTest.java b/src/test/java/org/web3j/console/account/AccountManagerTest.java index 34fb819..93b4b6e 100644 --- a/src/test/java/org/web3j/console/account/AccountManagerTest.java +++ b/src/test/java/org/web3j/console/account/AccountManagerTest.java @@ -1,5 +1,21 @@ +/* + * Copyright 2020 Web3 Labs Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ package org.web3j.console.account; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + import okhttp3.Call; import okhttp3.ConnectionPool; import okhttp3.MediaType; @@ -8,16 +24,12 @@ import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; - import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.web3j.console.config.CliConfig; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; +import org.web3j.console.config.CliConfig; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; @@ -47,14 +59,24 @@ public void testAccountCreation() throws IOException { OkHttpClient mockedOkHttpClient = mock(OkHttpClient.class); Call call = mock(Call.class); ConnectionPool connectionPool = mock(ConnectionPool.class); - AccountManager accountManager = new AccountManager(new CliConfig("", "", "", "", "", ""), mockedOkHttpClient); - Request request = accountManager.createRequest(accountManager.createRequestBody("test@gmail.com")); - Response response = new Response.Builder().protocol(Protocol.H2_PRIOR_KNOWLEDGE).message("") - .body(ResponseBody.create("{\n" + - " \"token\": \"8190c700-1f10-4c50-8bb2-1ce78bf0412b\",\n" + - " \"createdTimestamp\": \"1583234909601\"\n" + - "}", MediaType.parse("application/json"))) - .code(200).request(request).build(); + AccountManager accountManager = + new AccountManager(new CliConfig("", "", "", "", "", ""), mockedOkHttpClient); + Request request = + accountManager.createRequest(accountManager.createRequestBody("test@gmail.com")); + Response response = + new Response.Builder() + .protocol(Protocol.H2_PRIOR_KNOWLEDGE) + .message("") + .body( + ResponseBody.create( + "{\n" + + " \"token\": \"8190c700-1f10-4c50-8bb2-1ce78bf0412b\",\n" + + " \"createdTimestamp\": \"1583234909601\"\n" + + "}", + MediaType.parse("application/json"))) + .code(200) + .request(request) + .build(); when(call.execute()).thenReturn(response); when(mockedOkHttpClient.newCall(any(Request.class))).thenReturn(call); when(mockedOkHttpClient.connectionPool()).thenReturn(connectionPool); @@ -62,5 +84,4 @@ public void testAccountCreation() throws IOException { accountManager.createAccount("test@gmail.com"); Assertions.assertTrue(outContent.toString().contains("Account created successfully.")); } - }