Skip to content

Commit 864661b

Browse files
committed
refactoring
1 parent d42335b commit 864661b

File tree

6 files changed

+44
-45
lines changed

6 files changed

+44
-45
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'io.visual-regression-tracker.sdk-java'
2-
version '2.0.0'
2+
version '3.1.0'
33

44
apply plugin: 'java'
55
apply plugin: "io.freefair.lombok"

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
@Builder
77
@Getter
88
public class TestRunOptions {
9-
String os;
10-
String browser;
11-
String viewport;
12-
String device;
9+
private final String os;
10+
private final String browser;
11+
private final String viewport;
12+
private final String device;
1313
@Builder.Default
14-
Integer diffTollerancePercent = 1;
14+
private final Integer diffTollerancePercent = 1;
1515
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Optional;
1616

1717
public class VisualRegressionTracker {
18-
static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
18+
private static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
1919
String apiKeyHeaderName = "apiKey";
2020
Gson gson = new Gson();
2121
VisualRegressionTrackerConfig visualRegressionTrackerConfig;
@@ -29,18 +29,18 @@ public VisualRegressionTracker(VisualRegressionTrackerConfig visualRegressionTra
2929
this.client = new OkHttpClient();
3030
}
3131

32-
void startBuild() throws IOException {
32+
protected void startBuild() throws IOException {
3333
if (this.buildId == null) {
3434
BuildRequest newBuild = BuildRequest.builder()
35-
.branchName(this.visualRegressionTrackerConfig.branchName)
36-
.project(this.visualRegressionTrackerConfig.project)
35+
.branchName(this.visualRegressionTrackerConfig.getBranchName())
36+
.project(this.visualRegressionTrackerConfig.getProject())
3737
.build();
3838

3939
RequestBody body = RequestBody.create(gson.toJson(newBuild), JSON);
4040

4141
Request request = new Request.Builder()
42-
.url(this.visualRegressionTrackerConfig.apiUrl.concat("/builds"))
43-
.addHeader(apiKeyHeaderName, this.visualRegressionTrackerConfig.apiKey)
42+
.url(this.visualRegressionTrackerConfig.getApiUrl().concat("/builds"))
43+
.addHeader(apiKeyHeaderName, this.visualRegressionTrackerConfig.getApiKey())
4444
.post(body)
4545
.build();
4646

@@ -64,11 +64,11 @@ void startBuild() throws IOException {
6464
}
6565
}
6666

67-
TestRunResponse submitTestRun(String name, String imageBase64, TestRunOptions testRunOptions) throws IOException {
67+
protected TestRunResponse submitTestRun(String name, String imageBase64, TestRunOptions testRunOptions) throws IOException {
6868
TestRunRequest newTestRun = TestRunRequest.builder()
6969
.projectId(this.projectId)
7070
.buildId(this.buildId)
71-
.branchName(this.visualRegressionTrackerConfig.branchName)
71+
.branchName(this.visualRegressionTrackerConfig.getBranchName())
7272
.name(name)
7373
.imageBase64(imageBase64)
7474
.os(testRunOptions.getOs())
@@ -81,8 +81,8 @@ TestRunResponse submitTestRun(String name, String imageBase64, TestRunOptions te
8181
RequestBody body = RequestBody.create(gson.toJson(newTestRun), JSON);
8282

8383
Request request = new Request.Builder()
84-
.url(this.visualRegressionTrackerConfig.apiUrl.concat("/test-runs"))
85-
.addHeader(apiKeyHeaderName, this.visualRegressionTrackerConfig.apiKey)
84+
.url(this.visualRegressionTrackerConfig.getApiUrl().concat("/test-runs"))
85+
.addHeader(apiKeyHeaderName, this.visualRegressionTrackerConfig.getApiKey())
8686
.post(body)
8787
.build();
8888

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.visual_regression_tracker.sdk_java;
22

33
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.Setter;
46

7+
@Data
58
@AllArgsConstructor
69
public class VisualRegressionTrackerConfig {
7-
String apiUrl;
8-
String project;
9-
String apiKey;
10-
String branchName;
10+
private String apiUrl;
11+
private String project;
12+
private String apiKey;
13+
private String branchName;
1114
}

src/main/java/io/visual_regression_tracker/sdk_java/response/TestRunResponse.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
@Builder
88
@Getter
99
public class TestRunResponse {
10-
String url;
11-
TestRunStatus status;
12-
// not used for now
13-
// int pixelMisMatchCount;
14-
// float diffPercent;
15-
// float diffTollerancePercent;
10+
private final String url;
11+
private final TestRunStatus status;
1612
}

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,40 @@
2020
import java.io.IOException;
2121

2222
public class VisualRegressionTrackerTest {
23-
Gson gson = new Gson();
24-
MockWebServer server;
25-
VisualRegressionTracker vrt;
26-
VisualRegressionTrackerConfig config = new VisualRegressionTrackerConfig(
23+
private final Gson gson = new Gson();
24+
private final VisualRegressionTrackerConfig config = new VisualRegressionTrackerConfig(
2725
"http://localhost",
2826
"733c148e-ef70-4e6d-9ae5-ab22263697cc",
2927
"XHGDZDFD3GMJDNM87JKEMP0JS1G5",
3028
"develop"
3129
);
30+
private MockWebServer server;
31+
private VisualRegressionTracker vrt;
3232

3333
@SneakyThrows
3434
@BeforeMethod
35-
void setup() {
35+
private void setup() {
3636
server = new MockWebServer();
3737
server.start();
3838

3939
// target to mock server
40-
this.config.apiUrl = server.url("/").toString();
40+
this.config.setApiUrl(server.url("/").toString());
4141
vrt = new VisualRegressionTracker(config);
4242
}
4343

4444
@SneakyThrows
4545
@AfterMethod
46-
void tearDown() {
46+
private void tearDown() {
4747
server.shutdown();
4848
}
4949

5050
@Test
51-
void shouldStartBuild() throws IOException, InterruptedException {
51+
public void shouldStartBuild() throws IOException, InterruptedException {
5252
String buildId = "123123";
5353
String projectId = "projectId";
5454
BuildRequest buildRequest = BuildRequest.builder()
55-
.branchName(this.config.branchName)
56-
.project(this.config.project)
55+
.branchName(this.config.getBranchName())
56+
.project(this.config.getProject())
5757
.build();
5858
BuildResponse buildResponse = BuildResponse.builder()
5959
.id(buildId)
@@ -66,14 +66,14 @@ void shouldStartBuild() throws IOException, InterruptedException {
6666
vrt.startBuild();
6767

6868
RecordedRequest request = server.takeRequest();
69-
MatcherAssert.assertThat(request.getHeader(vrt.apiKeyHeaderName), CoreMatchers.is(config.apiKey));
69+
MatcherAssert.assertThat(request.getHeader(vrt.apiKeyHeaderName), CoreMatchers.is(config.getApiKey()));
7070
MatcherAssert.assertThat(request.getBody().readUtf8(), CoreMatchers.is(gson.toJson(buildRequest)));
7171
MatcherAssert.assertThat(vrt.buildId, CoreMatchers.is(buildId));
7272
MatcherAssert.assertThat(vrt.projectId, CoreMatchers.is(projectId));
7373
}
7474

7575
@Test
76-
void shouldThrowExceptionIfProjectNotFound() throws IOException {
76+
public void shouldThrowExceptionIfProjectNotFound() throws IOException {
7777
server.enqueue(new MockResponse()
7878
.setResponseCode(404)
7979
.setBody("{\r\n \"statusCode\": 404,\r\n \"message\": \"Project not found\"\r\n}"));
@@ -88,7 +88,7 @@ void shouldThrowExceptionIfProjectNotFound() throws IOException {
8888
}
8989

9090
@Test
91-
void shouldThrowExceptionIfUnauthorized() throws IOException {
91+
public void shouldThrowExceptionIfUnauthorized() throws IOException {
9292
server.enqueue(new MockResponse()
9393
.setResponseCode(401)
9494
.setBody("{\r\n \"statusCode\": 401,\r\n \"message\": \"Unauthorized\"\r\n}"));
@@ -103,7 +103,7 @@ void shouldThrowExceptionIfUnauthorized() throws IOException {
103103
}
104104

105105
@Test
106-
void shouldSubmitTestRun() throws IOException, InterruptedException {
106+
public void shouldSubmitTestRun() throws IOException, InterruptedException {
107107
String buildId = "123123";
108108
String projectId = "projectId";
109109
String name = "Test name";
@@ -117,7 +117,7 @@ void shouldSubmitTestRun() throws IOException, InterruptedException {
117117
.build();
118118
TestRunRequest testRunRequest = TestRunRequest.builder()
119119
.projectId(projectId)
120-
.branchName(config.branchName)
120+
.branchName(config.getBranchName())
121121
.buildId(buildId)
122122
.name(name)
123123
.imageBase64(imageBase64)
@@ -137,7 +137,7 @@ void shouldSubmitTestRun() throws IOException, InterruptedException {
137137
TestRunResponse result = vrt.submitTestRun(name, imageBase64, testRunOptions);
138138

139139
RecordedRequest request = server.takeRequest();
140-
MatcherAssert.assertThat(request.getHeader(vrt.apiKeyHeaderName), CoreMatchers.is(config.apiKey));
140+
MatcherAssert.assertThat(request.getHeader(vrt.apiKeyHeaderName), CoreMatchers.is(config.getApiKey()));
141141
MatcherAssert.assertThat(request.getBody().readUtf8(), CoreMatchers.is(gson.toJson(testRunRequest)));
142142
MatcherAssert.assertThat(gson.toJson(result), CoreMatchers.is(gson.toJson(testRunResponse)));
143143
}
@@ -163,7 +163,7 @@ public Object[][] shouldTrackThrowExceptionCases() {
163163
}
164164

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

@@ -190,7 +190,7 @@ public Object[][] shouldTrackPassCases() {
190190
}
191191

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

@@ -199,7 +199,7 @@ void shouldTrackPass(TestRunResponse testRunResponse) throws IOException {
199199
}
200200

201201
@Test()
202-
void shouldTrackOverload() throws IOException {
202+
public void shouldTrackOverload() throws IOException {
203203
VisualRegressionTracker vrtMocked = Mockito.mock(VisualRegressionTracker.class);
204204

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

0 commit comments

Comments
 (0)