Skip to content

Commit

Permalink
Merge pull request #107 from proximax-storage/issue/106-test-coverage
Browse files Browse the repository at this point in the history
Improvements for code coverage
  • Loading branch information
tonowie authored Aug 5, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 1a39f26 + f8d242b commit c63779f
Showing 47 changed files with 4,419 additions and 2,926 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -37,13 +37,13 @@ install:
# download dependencies (at least most of them)
- ./gradlew downloadDependencies --console=plain

script:
# build and test the app
- ./gradlew build jacocoTestReport coveralls --console=plain

# add publishing stage that publishes data out
jobs:
include:
- stage: build and coverage
jdk: openjdk8
script:
- ./gradlew build jacocoTestReport coveralls --console=plain
- stage: publish snapshot
jdk: openjdk8
if: type = push AND branch = master
86 changes: 55 additions & 31 deletions src/main/java/io/proximax/sdk/infrastructure/Http.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@

import java.io.IOException;

import org.apache.commons.lang3.Validate;

import com.google.gson.Gson;

import io.proximax.sdk.BlockchainApi;
@@ -26,36 +28,58 @@
* base HTTP repository implementation, keeping track of the API, HTTP client and mapper
*/
public class Http {
protected final BlockchainApi api;
protected final HttpClient client;
protected Gson gson;

/**
* create and initialize new instance for specified API
*
* @param api the main API
*/
Http(BlockchainApi api) {
this.api = api;
this.client = new OkHttpHttpClient(api);
// gson instance
this.gson = new Gson();
}

/**
* throw RuntimeException on error or return body of the response
*
* @param response response to examine
* @return body of the response as string
*/
static String mapStringOrError(final HttpResponse response) {
if (response.getCode() < 200 || response.getCode() > 299) {
throw new RuntimeException(response.getStatusMessage());
}
try {
return response.getBodyString();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
protected final BlockchainApi api;
protected final HttpClient client;
protected final Gson gson;

/**
* create and initialize new instance for specified API
*
* @param api the main API
*/
Http(BlockchainApi api) {
Validate.notNull(api, "api has to be provided");
this.api = api;
this.client = new OkHttpHttpClient(api);
// gson instance
this.gson = new Gson();
}

/**
* @return the api
*/
public BlockchainApi getApi() {
return api;
}

/**
* @return the client
*/
public HttpClient getClient() {
return client;
}

/**
* @return the gson
*/
public Gson getGson() {
return gson;
}

/**
* throw RuntimeException on error or return body of the response
*
* @param response response to examine
* @return body of the response as string
*/
static String mapStringOrError(final HttpResponse response) {
if (response.getCode() < 200 || response.getCode() > 299) {
throw new RuntimeException(response.getStatusMessage());
}
try {
return response.getBodyString();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
}
Loading

0 comments on commit c63779f

Please sign in to comment.