Skip to content

Commit c8565cf

Browse files
committed
Fixed codacy and CI errors.
1 parent c8d5116 commit c8565cf

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

.github/workflows/gradle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919

20-
- name: Set up JDK 1.8
20+
- name: Set up JDK 11
2121
uses: actions/setup-java@v1
2222
with:
23-
java-version: 1.8
23+
java-version: 11
2424

2525
- name: Grant execute permission for gradlew
2626
run: chmod +x gradlew

src/main/java/io/visual_regression_tracker/sdk_java/VisualRegressionTracker.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.time.Duration;
1616

1717
enum METHOD {
18+
GET,
1819
POST,
1920
PATCH
2021
}
@@ -141,17 +142,7 @@ private HttpResponse<String> getResponse(METHOD method, String url, HttpRequest.
141142
.header(API_KEY_HEADER, configuration.getApiKey())
142143
.header("Content-Type", "application/json;charset=UTF-8")
143144
.uri(URI.create(url));
144-
HttpRequest request;
145-
switch (method) {
146-
case PATCH:
147-
request = requestBuilder.method("PATCH", body).build();
148-
break;
149-
case POST:
150-
request = requestBuilder.POST(body).build();
151-
break;
152-
default:
153-
throw new IllegalStateException("Not implemented: " + method);
154-
}
145+
HttpRequest request = getRequest(method, body, requestBuilder);
155146
HttpResponse<String> response = HttpClient.newBuilder()
156147
.version(HttpClient.Version.HTTP_1_1)
157148
.connectTimeout(Duration.ofSeconds(configuration.getHttpTimeoutInSeconds()))
@@ -160,6 +151,17 @@ private HttpResponse<String> getResponse(METHOD method, String url, HttpRequest.
160151
return response;
161152
}
162153

154+
protected HttpRequest getRequest(METHOD method, HttpRequest.BodyPublisher body, HttpRequest.Builder requestBuilder) {
155+
switch (method) {
156+
case PATCH:
157+
return requestBuilder.method("PATCH", body).build();
158+
case POST:
159+
return requestBuilder.POST(body).build();
160+
default:
161+
throw new UnsupportedOperationException("This method is not yet supported.");
162+
}
163+
}
164+
163165
protected <T> T handleResponse(HttpResponse<String> response, Class<T> classOfT) {
164166
String responseBody = response.body();
165167
if (!String.valueOf(response.statusCode()).startsWith("2")) {

src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
import static org.hamcrest.MatcherAssert.assertThat;
3333
import static org.mockito.ArgumentMatchers.any;
3434
import static org.mockito.ArgumentMatchers.anyString;
35-
import static org.mockito.Mockito.*;
35+
import static org.mockito.Mockito.doCallRealMethod;
36+
import static org.mockito.Mockito.mock;
37+
import static org.mockito.Mockito.reset;
38+
import static org.mockito.Mockito.times;
39+
import static org.mockito.Mockito.verify;
40+
import static org.mockito.Mockito.when;
3641

3742
public class VisualRegressionTrackerTest {
3843

@@ -355,6 +360,11 @@ public void httpTimeoutWorks() throws IOException, InterruptedException {
355360
assertThat(vrt.projectId, is(PROJECT_ID));
356361
}
357362

363+
@Test(expectedExceptions = UnsupportedOperationException.class, expectedExceptionsMessageRegExp = "This method is not yet supported.")
364+
public void methodNotSupported() {
365+
vrt.getRequest(METHOD.GET, null, null);
366+
}
367+
358368
@Test(expectedExceptions = HttpTimeoutException.class,
359369
expectedExceptionsMessageRegExp = "^(request timed out)$")
360370
public void httpTimeoutElapsed() throws IOException, InterruptedException {

0 commit comments

Comments
 (0)