Skip to content

Commit

Permalink
Spotless.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrouR committed Mar 4, 2020
1 parent d853e36 commit 64fc1b2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ apply {
repositories {

maven { url "https://dl.bintray.com/ethereum/maven/" }

}

test {
Expand Down
19 changes: 4 additions & 15 deletions src/main/java/org/web3j/console/account/AccountManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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());
}
Expand All @@ -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();
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/web3j/console/project/UnitTestCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 35 additions & 14 deletions src/test/java/org/web3j/console/account/AccountManagerTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -47,20 +59,29 @@ 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("[email protected]"));
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("[email protected]"));
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);
doNothing().when(connectionPool).evictAll();
accountManager.createAccount("[email protected]");
Assertions.assertTrue(outContent.toString().contains("Account created successfully."));
}

}

0 comments on commit 64fc1b2

Please sign in to comment.