16
16
import org .hamcrest .CoreMatchers ;
17
17
import org .hamcrest .MatcherAssert ;
18
18
import org .mockito .Mockito ;
19
+ import org .simplify4u .sjf4jmock .LoggerMock ;
20
+ import org .slf4j .Logger ;
19
21
import org .testng .annotations .AfterMethod ;
20
22
import org .testng .annotations .BeforeMethod ;
21
23
import org .testng .annotations .DataProvider ;
@@ -30,14 +32,17 @@ public class VisualRegressionTrackerTest {
30
32
"http://localhost" ,
31
33
"733c148e-ef70-4e6d-9ae5-ab22263697cc" ,
32
34
"XHGDZDFD3GMJDNM87JKEMP0JS1G5" ,
33
- "develop"
35
+ "develop" ,
36
+ false
34
37
);
35
38
private MockWebServer server ;
36
39
private VisualRegressionTracker vrt ;
37
40
38
41
@ SneakyThrows
39
42
@ BeforeMethod
40
43
public void setup () {
44
+ LoggerMock .clearInvocations ();
45
+
41
46
server = new MockWebServer ();
42
47
server .start ();
43
48
@@ -164,8 +169,8 @@ public void submitTestRunShouldThrowIfNotStarted() throws IOException {
164
169
MatcherAssert .assertThat (exceptionMessage , CoreMatchers .is ("Visual Regression Tracker has not been started" ));
165
170
}
166
171
167
- @ DataProvider (name = "trackShouldThrowExceptionCases " )
168
- public Object [][] trackShouldThrowExceptionCases () {
172
+ @ DataProvider (name = "trackErrorCases " )
173
+ public Object [][] trackErrorCases () {
169
174
return new Object [][]{
170
175
{
171
176
TestRunResponse .builder ()
@@ -184,9 +189,10 @@ public Object[][] trackShouldThrowExceptionCases() {
184
189
};
185
190
}
186
191
187
- @ Test (dataProvider = "trackShouldThrowExceptionCases " )
192
+ @ Test (dataProvider = "trackErrorCases " )
188
193
public void trackShouldThrowException (TestRunResponse testRunResponse , String expectedExceptionMessage ) throws IOException {
189
194
VisualRegressionTracker vrtMocked = Mockito .mock (VisualRegressionTracker .class );
195
+ vrtMocked .visualRegressionTrackerConfig = new VisualRegressionTrackerConfig ("" , "" , "" , "" , false );
190
196
Mockito .when (vrtMocked .submitTestRun (Mockito .anyString (), Mockito .anyString (), Mockito .any ())).thenReturn (testRunResponse );
191
197
192
198
Mockito .doCallRealMethod ().when (vrtMocked ).track (Mockito .anyString (), Mockito .anyString (), Mockito .any ());
@@ -199,6 +205,19 @@ public void trackShouldThrowException(TestRunResponse testRunResponse, String ex
199
205
MatcherAssert .assertThat (exceptionMessage , CoreMatchers .is (expectedExceptionMessage ));
200
206
}
201
207
208
+ @ Test (dataProvider = "trackErrorCases" )
209
+ public void trackShouldLogSevere (TestRunResponse testRunResponse , String expectedExceptionMessage ) throws IOException {
210
+ Logger loggerMock = LoggerMock .getLoggerMock (VisualRegressionTracker .class );
211
+ VisualRegressionTracker vrtMocked = Mockito .mock (VisualRegressionTracker .class );
212
+ vrtMocked .visualRegressionTrackerConfig = new VisualRegressionTrackerConfig ("" , "" , "" , "" , true );
213
+ Mockito .when (vrtMocked .submitTestRun (Mockito .anyString (), Mockito .anyString (), Mockito .any ())).thenReturn (testRunResponse );
214
+
215
+ Mockito .doCallRealMethod ().when (vrtMocked ).track (Mockito .anyString (), Mockito .anyString (), Mockito .any ());
216
+ vrtMocked .track ("name" , "image" , TestRunOptions .builder ().build ());
217
+
218
+ Mockito .verify (loggerMock ).error (expectedExceptionMessage );
219
+ }
220
+
202
221
@ DataProvider (name = "shouldTrackPassCases" )
203
222
public Object [][] shouldTrackPassCases () {
204
223
return new Object [][]{
0 commit comments