1
1
package io .visual_regression_tracker .sdk_java ;
2
2
3
+ import java .io .IOException ;
4
+ import java .util .Arrays ;
5
+ import java .util .Objects ;
6
+
3
7
import ch .qos .logback .classic .Level ;
4
8
import ch .qos .logback .classic .Logger ;
5
9
import ch .qos .logback .classic .spi .ILoggingEvent ;
23
27
import org .testng .annotations .DataProvider ;
24
28
import org .testng .annotations .Test ;
25
29
26
- import java .io .IOException ;
27
- import java .util .Objects ;
28
-
29
30
import static org .hamcrest .CoreMatchers .containsString ;
30
31
import static org .hamcrest .CoreMatchers .is ;
31
32
import static org .hamcrest .MatcherAssert .assertThat ;
34
35
import static org .mockito .Mockito .doCallRealMethod ;
35
36
import static org .mockito .Mockito .mock ;
36
37
import static org .mockito .Mockito .reset ;
38
+ import static org .mockito .Mockito .times ;
37
39
import static org .mockito .Mockito .verify ;
38
40
import static org .mockito .Mockito .when ;
39
- import static org .mockito .Mockito .times ;
40
41
41
42
public class VisualRegressionTrackerTest {
42
43
@@ -81,16 +82,16 @@ public void tearDown() {
81
82
@ Test
82
83
public void shouldStartBuild () throws IOException , InterruptedException {
83
84
BuildRequest buildRequest = BuildRequest .builder ()
84
- .branchName (this .config .getBranchName ())
85
- .project (this .config .getProject ())
86
- .build ();
85
+ .branchName (this .config .getBranchName ())
86
+ .project (this .config .getProject ())
87
+ .build ();
87
88
BuildResponse buildResponse = BuildResponse .builder ()
88
- .id (BUILD_ID )
89
- .projectId (PROJECT_ID )
90
- .build ();
89
+ .id (BUILD_ID )
90
+ .projectId (PROJECT_ID )
91
+ .build ();
91
92
server .enqueue (new MockResponse ()
92
- .setResponseCode (200 )
93
- .setBody (gson .toJson (buildResponse )));
93
+ .setResponseCode (200 )
94
+ .setBody (gson .toJson (buildResponse )));
94
95
95
96
vrt .start ();
96
97
@@ -106,11 +107,11 @@ public void shouldStopBuild() throws IOException, InterruptedException {
106
107
vrt .buildId = BUILD_ID ;
107
108
vrt .projectId = PROJECT_ID ;
108
109
BuildResponse buildResponse = BuildResponse .builder ()
109
- .id (BUILD_ID )
110
- .build ();
110
+ .id (BUILD_ID )
111
+ .build ();
111
112
server .enqueue (new MockResponse ()
112
- .setResponseCode (200 )
113
- .setBody (gson .toJson (buildResponse )));
113
+ .setResponseCode (200 )
114
+ .setBody (gson .toJson (buildResponse )));
114
115
115
116
vrt .stop ();
116
117
@@ -129,27 +130,34 @@ public void stopShouldThrowExceptionIfNotStarted() throws IOException {
129
130
@ Test
130
131
public void shouldSubmitTestRun () throws IOException , InterruptedException {
131
132
TestRunOptions testRunOptions = TestRunOptions .builder ()
132
- .device ("Device" )
133
- .os ("OS" )
134
- .browser ("Browser" )
135
- .viewport ("Viewport" )
136
- .diffTollerancePercent (0.5f )
137
- .build ();
133
+ .device ("Device" )
134
+ .os ("OS" )
135
+ .browser ("Browser" )
136
+ .viewport ("Viewport" )
137
+ .diffTollerancePercent (0.5f )
138
+ .ignoredAreas (Arrays .asList (IgnoredArea .builder ()
139
+ .x (100L )
140
+ .y (100L )
141
+ .height (1L )
142
+ .width (1L )
143
+ .build ()))
144
+ .build ();
138
145
TestRunRequest testRunRequest = TestRunRequest .builder ()
139
- .projectId (PROJECT_ID )
140
- .branchName (config .getBranchName ())
141
- .buildId (BUILD_ID )
142
- .name (NAME )
143
- .imageBase64 (IMAGE_BASE_64 )
144
- .os (testRunOptions .getOs ())
145
- .browser (testRunOptions .getBrowser ())
146
- .viewport (testRunOptions .getViewport ())
147
- .device (testRunOptions .getDevice ())
148
- .diffTollerancePercent (testRunOptions .getDiffTollerancePercent ())
149
- .build ();
146
+ .projectId (PROJECT_ID )
147
+ .branchName (config .getBranchName ())
148
+ .buildId (BUILD_ID )
149
+ .name (NAME )
150
+ .imageBase64 (IMAGE_BASE_64 )
151
+ .os (testRunOptions .getOs ())
152
+ .browser (testRunOptions .getBrowser ())
153
+ .viewport (testRunOptions .getViewport ())
154
+ .device (testRunOptions .getDevice ())
155
+ .diffTollerancePercent (testRunOptions .getDiffTollerancePercent ())
156
+ .ignoredAreas (testRunOptions .getIgnoredAreas ())
157
+ .build ();
150
158
TestRunResponse testRunResponse = TestRunResponse .builder ()
151
- .status (TestRunStatus .UNRESOLVED )
152
- .build ();
159
+ .status (TestRunStatus .UNRESOLVED )
160
+ .build ();
153
161
server .enqueue (new MockResponse ().setBody (gson .toJson (testRunResponse )));
154
162
vrt .buildId = BUILD_ID ;
155
163
vrt .projectId = PROJECT_ID ;
@@ -173,24 +181,24 @@ public void submitTestRunShouldThrowIfNotStarted() throws IOException {
173
181
174
182
@ DataProvider (name = "trackErrorCases" )
175
183
public Object [][] trackErrorCases () {
176
- return new Object [][]{
184
+ return new Object [][] {
177
185
{
178
186
TestRunResponse .builder ()
179
- .url ("https://someurl.com/test/123123" )
180
- .imageName ("imageName" )
181
- .baselineName ("baselineName" )
182
- .diffName ("diffName" )
183
- .status (TestRunStatus .UNRESOLVED )
187
+ .url ("https://someurl.com/test/123123" )
188
+ .imageName ("imageName" )
189
+ .baselineName ("baselineName" )
190
+ .diffName ("diffName" )
191
+ .status (TestRunStatus .UNRESOLVED )
184
192
.build (),
185
193
"Difference found: https://someurl.com/test/123123"
186
194
},
187
195
{
188
196
TestRunResponse .builder ()
189
- .url ("https://someurl.com/test/123123" )
190
- .imageName ("imageName" )
191
- .baselineName ("baselineName" )
192
- .diffName ("diffName" )
193
- .status (TestRunStatus .NEW )
197
+ .url ("https://someurl.com/test/123123" )
198
+ .imageName ("imageName" )
199
+ .baselineName ("baselineName" )
200
+ .diffName ("diffName" )
201
+ .status (TestRunStatus .NEW )
194
202
.build (),
195
203
"No baseline: https://someurl.com/test/123123"
196
204
}
@@ -228,19 +236,19 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte
228
236
229
237
@ DataProvider (name = "shouldTrackPassCases" )
230
238
public Object [][] shouldTrackPassCases () {
231
- return new Object [][]{
239
+ return new Object [][] {
232
240
{
233
241
TestRunResponse .builder ()
234
- .id ("someId" )
235
- .imageName ("imageName" )
236
- .baselineName ("baselineName" )
237
- .diffName ("diffName" )
238
- .diffPercent (12.32f )
239
- .diffTollerancePercent (0.01f )
240
- .pixelMisMatchCount (1 )
241
- .merge (false )
242
- .url ("https://someurl.com/test/123123" )
243
- .status (TestRunStatus .OK )
242
+ .id ("someId" )
243
+ .imageName ("imageName" )
244
+ .baselineName ("baselineName" )
245
+ .diffName ("diffName" )
246
+ .diffPercent (12.32f )
247
+ .diffTollerancePercent (0.01f )
248
+ .pixelMisMatchCount (1 )
249
+ .merge (false )
250
+ .url ("https://someurl.com/test/123123" )
251
+ .status (TestRunStatus .OK )
244
252
.build (),
245
253
}
246
254
};
@@ -270,7 +278,7 @@ public void shouldTrackOverload() throws IOException {
270
278
271
279
@ DataProvider (name = "shouldReturnIsStartedCases" )
272
280
public Object [][] shouldReturnIsStartedCases () {
273
- return new Object [][]{
281
+ return new Object [][] {
274
282
{null , null , false },
275
283
{null , "some" , false },
276
284
{"some" , null , false },
@@ -291,22 +299,22 @@ public void shouldReturnIsStarted(String buildId, String projectId, boolean expe
291
299
@ Test
292
300
public void handleRequestShouldThrowIfNotSuccess () throws IOException {
293
301
String error = "{\n " +
294
- " \" statusCode\" : 404,\n " +
295
- " \" message\" : \" Project not found\" \n " +
296
- "}" ;
302
+ " \" statusCode\" : 404,\n " +
303
+ " \" message\" : \" Project not found\" \n " +
304
+ "}" ;
297
305
Request mockRequest = new Request .Builder ()
298
- .url (config .getApiUrl ())
299
- .build ();
306
+ .url (config .getApiUrl ())
307
+ .build ();
300
308
301
309
String exceptionMessage = "" ;
302
310
try {
303
311
vrt .handleResponse (new Response .Builder ()
304
- .request (mockRequest )
305
- .protocol (Protocol .HTTP_2 )
306
- .code (404 )
307
- .message ("Not found" )
308
- .body (ResponseBody .create (error , VisualRegressionTracker .JSON ))
309
- .build (), Object .class );
312
+ .request (mockRequest )
313
+ .protocol (Protocol .HTTP_2 )
314
+ .code (404 )
315
+ .message ("Not found" )
316
+ .body (ResponseBody .create (error , VisualRegressionTracker .JSON ))
317
+ .build (), Object .class );
310
318
} catch (TestRunException ex ) {
311
319
exceptionMessage = ex .getMessage ();
312
320
}
0 commit comments