Skip to content

Commit 2d839c9

Browse files
committed
updated
1 parent c261b68 commit 2d839c9

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import okhttp3.Request;
1111
import okhttp3.RequestBody;
1212
import okhttp3.Response;
13-
import okhttp3.ResponseBody;
1413

1514
import java.io.IOException;
1615
import java.util.Optional;
@@ -56,9 +55,11 @@ void startBuild() throws IOException {
5655
String responseBody = Optional.ofNullable(response.body())
5756
.orElseThrow(() -> new TestRunException("Cannot get response body"))
5857
.string();
59-
BuildResponse buildDTO = new Gson().fromJson(responseBody, BuildResponse.class);
60-
this.buildId = buildDTO.getId();
61-
this.projectId = buildDTO.getProjectId();
58+
BuildResponse buildDTO = gson.fromJson(responseBody, BuildResponse.class);
59+
this.buildId = Optional.ofNullable(buildDTO.getId())
60+
.orElseThrow(() -> new TestRunException("Build id is null"));
61+
this.projectId = Optional.ofNullable(buildDTO.getProjectId())
62+
.orElseThrow(() -> new TestRunException("Project id is null"));
6263
}
6364
}
6465
}
@@ -85,8 +86,11 @@ TestRunResponse submitTestRun(String name, String imageBase64, TestRunOptions te
8586
.post(body)
8687
.build();
8788

88-
try (ResponseBody responseBody = client.newCall(request).execute().body()) {
89-
return gson.fromJson(responseBody.string(), TestRunResponse.class);
89+
try (Response response = client.newCall(request).execute()) {
90+
String responseBody = Optional.ofNullable(response.body())
91+
.orElseThrow(() -> new TestRunException("Cannot get response body"))
92+
.string();
93+
return gson.fromJson(responseBody, TestRunResponse.class);
9094
}
9195
}
9296

@@ -95,11 +99,14 @@ public void track(String name, String imageBase64, TestRunOptions testRunOptions
9599

96100
TestRunResponse testResultDTO = this.submitTestRun(name, imageBase64, testRunOptions);
97101

98-
if (testResultDTO.getStatus().equals(TestRunStatus.NEW)) {
102+
TestRunStatus status = Optional.ofNullable(testResultDTO.getStatus())
103+
.orElseThrow(() -> new TestRunException("Status is null"));
104+
105+
if (status.equals(TestRunStatus.NEW)) {
99106
throw new TestRunException("No baseline: ".concat(testResultDTO.getUrl()));
100107
}
101108

102-
if (testResultDTO.getStatus().equals(TestRunStatus.UNRESOLVED)) {
109+
if (status.equals(TestRunStatus.UNRESOLVED)) {
103110
throw new TestRunException("Difference found: ".concat(testResultDTO.getUrl()));
104111
}
105112
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class VisualRegressionTrackerTest {
2424
MockWebServer server;
2525
VisualRegressionTracker vrt;
2626
VisualRegressionTrackerConfig config = new VisualRegressionTrackerConfig(
27-
"http://localhost",
27+
"http://localhost:4200",
2828
"733c148e-ef70-4e6d-9ae5-ab22263697cc",
2929
"XHGDZDFD3GMJDNM87JKEMP0JS1G5",
3030
"develop"
@@ -160,7 +160,7 @@ public Object[][] shouldTrackThrowExceptionCases() {
160160
}
161161

162162
@Test(dataProvider = "shouldTrackThrowExceptionCases")
163-
public void shouldTrackThrowException(TestRunResponse testRunResponse, String expectedExceptionMessage) throws IOException {
163+
void shouldTrackThrowException(TestRunResponse testRunResponse, String expectedExceptionMessage) throws IOException {
164164
VisualRegressionTracker vrtMocked = Mockito.mock(VisualRegressionTracker.class);
165165
Mockito.when(vrtMocked.submitTestRun(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(testRunResponse);
166166

@@ -187,7 +187,7 @@ public Object[][] shouldTrackPassCases() {
187187
}
188188

189189
@Test(dataProvider = "shouldTrackPassCases")
190-
public void shouldTrackPass(TestRunResponse testRunResponse) throws IOException {
190+
void shouldTrackPass(TestRunResponse testRunResponse) throws IOException {
191191
VisualRegressionTracker vrtMocked = Mockito.mock(VisualRegressionTracker.class);
192192
Mockito.when(vrtMocked.submitTestRun(Mockito.anyString(), Mockito.anyString(), Mockito.any())).thenReturn(testRunResponse);
193193

@@ -196,7 +196,7 @@ public void shouldTrackPass(TestRunResponse testRunResponse) throws IOException
196196
}
197197

198198
@Test()
199-
public void shouldTrackOverload() throws IOException {
199+
void shouldTrackOverload() throws IOException {
200200
VisualRegressionTracker vrtMocked = Mockito.mock(VisualRegressionTracker.class);
201201

202202
Mockito.doCallRealMethod().when(vrtMocked).track(Mockito.anyString(), Mockito.anyString());

0 commit comments

Comments
 (0)