Skip to content

Commit c63779f

Browse files
authored
Merge pull request #107 from proximax-storage/issue/106-test-coverage
Improvements for code coverage
2 parents 1a39f26 + f8d242b commit c63779f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4419
-2926
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ install:
3737
# download dependencies (at least most of them)
3838
- ./gradlew downloadDependencies --console=plain
3939

40-
script:
41-
# build and test the app
42-
- ./gradlew build jacocoTestReport coveralls --console=plain
43-
4440
# add publishing stage that publishes data out
4541
jobs:
4642
include:
43+
- stage: build and coverage
44+
jdk: openjdk8
45+
script:
46+
- ./gradlew build jacocoTestReport coveralls --console=plain
4747
- stage: publish snapshot
4848
jdk: openjdk8
4949
if: type = push AND branch = master

src/main/java/io/proximax/sdk/infrastructure/Http.java

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.IOException;
2020

21+
import org.apache.commons.lang3.Validate;
22+
2123
import com.google.gson.Gson;
2224

2325
import io.proximax.sdk.BlockchainApi;
@@ -26,36 +28,58 @@
2628
* base HTTP repository implementation, keeping track of the API, HTTP client and mapper
2729
*/
2830
public class Http {
29-
protected final BlockchainApi api;
30-
protected final HttpClient client;
31-
protected Gson gson;
32-
33-
/**
34-
* create and initialize new instance for specified API
35-
*
36-
* @param api the main API
37-
*/
38-
Http(BlockchainApi api) {
39-
this.api = api;
40-
this.client = new OkHttpHttpClient(api);
41-
// gson instance
42-
this.gson = new Gson();
43-
}
44-
45-
/**
46-
* throw RuntimeException on error or return body of the response
47-
*
48-
* @param response response to examine
49-
* @return body of the response as string
50-
*/
51-
static String mapStringOrError(final HttpResponse response) {
52-
if (response.getCode() < 200 || response.getCode() > 299) {
53-
throw new RuntimeException(response.getStatusMessage());
54-
}
55-
try {
56-
return response.getBodyString();
57-
} catch (IOException e) {
58-
throw new RuntimeException(e.getMessage());
59-
}
31+
protected final BlockchainApi api;
32+
protected final HttpClient client;
33+
protected final Gson gson;
34+
35+
/**
36+
* create and initialize new instance for specified API
37+
*
38+
* @param api the main API
39+
*/
40+
Http(BlockchainApi api) {
41+
Validate.notNull(api, "api has to be provided");
42+
this.api = api;
43+
this.client = new OkHttpHttpClient(api);
44+
// gson instance
45+
this.gson = new Gson();
46+
}
47+
48+
/**
49+
* @return the api
50+
*/
51+
public BlockchainApi getApi() {
52+
return api;
53+
}
54+
55+
/**
56+
* @return the client
57+
*/
58+
public HttpClient getClient() {
59+
return client;
60+
}
61+
62+
/**
63+
* @return the gson
64+
*/
65+
public Gson getGson() {
66+
return gson;
67+
}
68+
69+
/**
70+
* throw RuntimeException on error or return body of the response
71+
*
72+
* @param response response to examine
73+
* @return body of the response as string
74+
*/
75+
static String mapStringOrError(final HttpResponse response) {
76+
if (response.getCode() < 200 || response.getCode() > 299) {
77+
throw new RuntimeException(response.getStatusMessage());
78+
}
79+
try {
80+
return response.getBodyString();
81+
} catch (IOException e) {
82+
throw new RuntimeException(e.getMessage());
83+
}
6084
}
6185
}

0 commit comments

Comments
 (0)