11package io .visual_regression_tracker .sdk_java ;
22
3+ import java .io .IOException ;
4+ import java .util .Arrays ;
5+ import java .util .Objects ;
6+
37import ch .qos .logback .classic .Level ;
48import ch .qos .logback .classic .Logger ;
59import ch .qos .logback .classic .spi .ILoggingEvent ;
2327import org .testng .annotations .DataProvider ;
2428import org .testng .annotations .Test ;
2529
26- import java .io .IOException ;
27- import java .util .Objects ;
28-
2930import static org .hamcrest .CoreMatchers .containsString ;
3031import static org .hamcrest .CoreMatchers .is ;
3132import static org .hamcrest .MatcherAssert .assertThat ;
3435import static org .mockito .Mockito .doCallRealMethod ;
3536import static org .mockito .Mockito .mock ;
3637import static org .mockito .Mockito .reset ;
38+ import static org .mockito .Mockito .times ;
3739import static org .mockito .Mockito .verify ;
3840import static org .mockito .Mockito .when ;
39- import static org .mockito .Mockito .times ;
4041
4142public class VisualRegressionTrackerTest {
4243
@@ -81,16 +82,16 @@ public void tearDown() {
8182 @ Test
8283 public void shouldStartBuild () throws IOException , InterruptedException {
8384 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 ();
8788 BuildResponse buildResponse = BuildResponse .builder ()
88- .id (BUILD_ID )
89- .projectId (PROJECT_ID )
90- .build ();
89+ .id (BUILD_ID )
90+ .projectId (PROJECT_ID )
91+ .build ();
9192 server .enqueue (new MockResponse ()
92- .setResponseCode (200 )
93- .setBody (gson .toJson (buildResponse )));
93+ .setResponseCode (200 )
94+ .setBody (gson .toJson (buildResponse )));
9495
9596 vrt .start ();
9697
@@ -106,11 +107,11 @@ public void shouldStopBuild() throws IOException, InterruptedException {
106107 vrt .buildId = BUILD_ID ;
107108 vrt .projectId = PROJECT_ID ;
108109 BuildResponse buildResponse = BuildResponse .builder ()
109- .id (BUILD_ID )
110- .build ();
110+ .id (BUILD_ID )
111+ .build ();
111112 server .enqueue (new MockResponse ()
112- .setResponseCode (200 )
113- .setBody (gson .toJson (buildResponse )));
113+ .setResponseCode (200 )
114+ .setBody (gson .toJson (buildResponse )));
114115
115116 vrt .stop ();
116117
@@ -129,27 +130,34 @@ public void stopShouldThrowExceptionIfNotStarted() throws IOException {
129130 @ Test
130131 public void shouldSubmitTestRun () throws IOException , InterruptedException {
131132 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 ();
138145 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 ();
150158 TestRunResponse testRunResponse = TestRunResponse .builder ()
151- .status (TestRunStatus .UNRESOLVED )
152- .build ();
159+ .status (TestRunStatus .UNRESOLVED )
160+ .build ();
153161 server .enqueue (new MockResponse ().setBody (gson .toJson (testRunResponse )));
154162 vrt .buildId = BUILD_ID ;
155163 vrt .projectId = PROJECT_ID ;
@@ -173,24 +181,24 @@ public void submitTestRunShouldThrowIfNotStarted() throws IOException {
173181
174182 @ DataProvider (name = "trackErrorCases" )
175183 public Object [][] trackErrorCases () {
176- return new Object [][]{
184+ return new Object [][] {
177185 {
178186 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 )
184192 .build (),
185193 "Difference found: https://someurl.com/test/123123"
186194 },
187195 {
188196 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 )
194202 .build (),
195203 "No baseline: https://someurl.com/test/123123"
196204 }
@@ -228,19 +236,19 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte
228236
229237 @ DataProvider (name = "shouldTrackPassCases" )
230238 public Object [][] shouldTrackPassCases () {
231- return new Object [][]{
239+ return new Object [][] {
232240 {
233241 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 )
244252 .build (),
245253 }
246254 };
@@ -270,7 +278,7 @@ public void shouldTrackOverload() throws IOException {
270278
271279 @ DataProvider (name = "shouldReturnIsStartedCases" )
272280 public Object [][] shouldReturnIsStartedCases () {
273- return new Object [][]{
281+ return new Object [][] {
274282 {null , null , false },
275283 {null , "some" , false },
276284 {"some" , null , false },
@@ -291,22 +299,22 @@ public void shouldReturnIsStarted(String buildId, String projectId, boolean expe
291299 @ Test
292300 public void handleRequestShouldThrowIfNotSuccess () throws IOException {
293301 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+ "}" ;
297305 Request mockRequest = new Request .Builder ()
298- .url (config .getApiUrl ())
299- .build ();
306+ .url (config .getApiUrl ())
307+ .build ();
300308
301309 String exceptionMessage = "" ;
302310 try {
303311 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 );
310318 } catch (TestRunException ex ) {
311319 exceptionMessage = ex .getMessage ();
312320 }
0 commit comments