1
1
package com .uid2 .shared .util ;
2
2
3
+ import ch .qos .logback .classic .spi .LoggerRemoteView ;
4
+ import org .junit .AfterClass ;
5
+ import org .junit .BeforeClass ;
6
+ import org .junit .jupiter .api .AfterEach ;
3
7
import org .junit .jupiter .api .BeforeEach ;
8
+ import org .junit .jupiter .api .Test ;
4
9
import org .junit .jupiter .params .ParameterizedTest ;
5
10
import org .junit .jupiter .params .provider .CsvSource ;
11
+ import org .mockito .MockedStatic ;
6
12
import org .mockito .MockitoAnnotations ;
7
13
import org .slf4j .Logger ;
8
14
import org .junit .Assert ;
9
15
import org .mockito .Mock ;
16
+ import org .slf4j .LoggerFactory ;
10
17
11
18
import static org .mockito .ArgumentMatchers .any ;
12
19
import static org .mockito .ArgumentMatchers .eq ;
13
- import static org .mockito .Mockito .times ;
14
- import static org .mockito .Mockito .verify ;
20
+ import static org .mockito .Mockito .*;
15
21
16
22
public class UrlEquivalenceValidatorTest {
17
23
18
- @ Mock
19
- private Logger loggerMock ;
24
+ private MockedStatic < LoggerFactory > mockedLoggerFactory ;
25
+ private static Logger mockedLogger = mock ( Logger . class ) ;
20
26
27
+ @ BeforeClass
28
+ public static void classSetup () {
29
+
30
+ }
21
31
@ BeforeEach
22
32
public void setup (){
23
- MockitoAnnotations .openMocks (this );
33
+ mockedLoggerFactory = mockStatic (LoggerFactory .class );
34
+ mockedLoggerFactory .when (() -> LoggerFactory .getLogger (any (Class .class ))).thenReturn (mockedLogger );
35
+ }
36
+
37
+ @ AfterEach
38
+ public void close () {
39
+ mockedLoggerFactory .close ();
24
40
}
25
41
26
42
@ ParameterizedTest
@@ -37,7 +53,7 @@ public void setup(){
37
53
"https://ade7-113-29-30-226.ngrok-free.app;https://ade7-113-29-30-226.ngrok-free.app/attest"
38
54
}, delimiter = ';' )
39
55
public void urls_equal (String first , String second ) {
40
- Assert .assertTrue (UrlEquivalenceValidator .areUrlsEquivalent (first , second , loggerMock ));
56
+ Assert .assertTrue (UrlEquivalenceValidator .areUrlsEquivalent (first , second ));
41
57
}
42
58
43
59
@ ParameterizedTest
@@ -51,7 +67,7 @@ public void urls_equal(String first, String second) {
51
67
"http://example.com:8081;http://example.com:8080/" ,
52
68
}, delimiter = ';' )
53
69
public void urls_not_equal (String first , String second ) {
54
- Assert .assertFalse (UrlEquivalenceValidator .areUrlsEquivalent (first , second , loggerMock ));
70
+ Assert .assertFalse (UrlEquivalenceValidator .areUrlsEquivalent (first , second ));
55
71
}
56
72
57
73
@ ParameterizedTest
@@ -63,8 +79,7 @@ public void urls_not_equal(String first, String second) {
63
79
"http://example1.com:abc;http://example2.com;URL could not be parsed to a valid URL. Given URL: http://example1.com:abc" ,
64
80
}, delimiter = ';' )
65
81
public void urls_invalid (String first , String second , String expectedError ) {
66
- Assert .assertFalse (UrlEquivalenceValidator .areUrlsEquivalent (first , second , loggerMock ));
67
- verify (loggerMock , times ( 1 ) ).error (eq (expectedError ), (Throwable ) any ());
82
+ Assert .assertFalse (UrlEquivalenceValidator .areUrlsEquivalent (first , second ));
83
+ verify (mockedLogger ).error (eq (expectedError ), (Throwable ) any ());
68
84
}
69
-
70
85
}
0 commit comments