Skip to content

Commit f12c1c1

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

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: 12 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,16 @@ 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+
}
161+
throw new UnsupportedOperationException("This method is not yet supported.");
162+
}
163+
163164
protected <T> T handleResponse(HttpResponse<String> response, Class<T> classOfT) {
164165
String responseBody = response.body();
165166
if (!String.valueOf(response.statusCode()).startsWith("2")) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.IOException;
2323
import java.net.http.HttpClient;
24+
import java.net.http.HttpRequest;
2425
import java.net.http.HttpResponse;
2526
import java.net.http.HttpTimeoutException;
2627
import java.util.Arrays;
@@ -32,7 +33,12 @@
3233
import static org.hamcrest.MatcherAssert.assertThat;
3334
import static org.mockito.ArgumentMatchers.any;
3435
import static org.mockito.ArgumentMatchers.anyString;
35-
import static org.mockito.Mockito.*;
36+
import static org.mockito.Mockito.doCallRealMethod;
37+
import static org.mockito.Mockito.mock;
38+
import static org.mockito.Mockito.reset;
39+
import static org.mockito.Mockito.times;
40+
import static org.mockito.Mockito.verify;
41+
import static org.mockito.Mockito.when;
3642

3743
public class VisualRegressionTrackerTest {
3844

@@ -355,6 +361,11 @@ public void httpTimeoutWorks() throws IOException, InterruptedException {
355361
assertThat(vrt.projectId, is(PROJECT_ID));
356362
}
357363

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

0 commit comments

Comments
 (0)