77
88import org .junit .jupiter .api .Test ;
99import org .mockito .MockedConstruction ;
10+ import org .mockito .MockedStatic ;
1011import org .mockito .Mockito ;
1112import org .slf4j .Logger ;
1213
1314import com .checkmarx .ast .wrapper .CxException ;
1415import com .checkmarx .ast .wrapper .CxWrapper ;
1516import com .checkmarx .eclipse .runner .Authenticator ;
17+ import com .checkmarx .eclipse .utils .CxLogger ;
1618import com .checkmarx .eclipse .utils .PluginConstants ;
1719
1820class AuthenticatorTest {
@@ -24,14 +26,15 @@ void testDoAuthenticationSuccess() throws Exception {
2426
2527 try (MockedConstruction <CxWrapper > mocked =
2628 Mockito .mockConstruction (CxWrapper .class ,
27- (mock , context ) -> when (mock .authValidate ()).thenReturn ("SUCCESS" ))) {
29+ (mock , context ) -> when (mock .authValidate ()).thenReturn ("SUCCESS" ));
30+ MockedStatic <CxLogger > mockedCxLogger = Mockito .mockStatic (CxLogger .class )) {
2831
2932 Authenticator authenticator = new Authenticator (mockLogger );
3033
3134 String result = authenticator .doAuthentication ("dummyKey" , "--param" );
3235
3336 assertEquals ("SUCCESS" , result );
34- verify (mockLogger ) .info ("Authentication Status: SUCCESS" );
37+ mockedCxLogger . verify (() -> CxLogger .info ("Authentication Status: SUCCESS" ) );
3538 }
3639 }
3740
@@ -43,17 +46,18 @@ void testDoAuthenticationIOException() throws Exception {
4346 try (MockedConstruction <CxWrapper > mocked =
4447 Mockito .mockConstruction (CxWrapper .class ,
4548 (mock , context ) -> when (mock .authValidate ())
46- .thenThrow (new IOException ("IO error" )))) {
49+ .thenThrow (new IOException ("IO error" )));
50+ MockedStatic <CxLogger > mockedCxLogger = Mockito .mockStatic (CxLogger .class )) {
4751
4852 Authenticator authenticator = new Authenticator (mockLogger );
4953
5054 String result = authenticator .doAuthentication ("dummyKey" , "--param" );
5155
5256 assertEquals ("IO error" , result );
53- verify (mockLogger ) .error (
54- eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "IO error" )),
55- any (IOException .class )
56- );
57+ mockedCxLogger . verify (() -> CxLogger .error (
58+ eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "IO error" )),
59+ any (IOException .class )
60+ ) );
5761 }
5862 }
5963
@@ -65,17 +69,18 @@ void testDoAuthenticationInterruptedException() throws Exception {
6569 try (MockedConstruction <CxWrapper > mocked =
6670 Mockito .mockConstruction (CxWrapper .class ,
6771 (mock , context ) -> when (mock .authValidate ())
68- .thenThrow (new InterruptedException ("Interrupted" )))) {
72+ .thenThrow (new InterruptedException ("Interrupted" )));
73+ MockedStatic <CxLogger > mockedCxLogger = Mockito .mockStatic (CxLogger .class )) {
6974
7075 Authenticator authenticator = new Authenticator (mockLogger );
7176
7277 String result = authenticator .doAuthentication ("dummyKey" , "--param" );
7378
7479 assertEquals ("Interrupted" , result );
75- verify (mockLogger ) .error (
76- eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "Interrupted" )),
77- any (InterruptedException .class )
78- );
80+ mockedCxLogger . verify (() -> CxLogger .error (
81+ eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "Interrupted" )),
82+ any (InterruptedException .class )
83+ ) );
7984 }
8085 }
8186
@@ -87,17 +92,18 @@ void testDoAuthenticationCxException() throws Exception {
8792 try (MockedConstruction <CxWrapper > mocked =
8893 Mockito .mockConstruction (CxWrapper .class ,
8994 (mock , context ) -> when (mock .authValidate ())
90- .thenThrow (new CxException (1 , "Cx error" )))) {
95+ .thenThrow (new CxException (1 , "Cx error" )));
96+ MockedStatic <CxLogger > mockedCxLogger = Mockito .mockStatic (CxLogger .class )) {
9197
9298 Authenticator authenticator = new Authenticator (mockLogger );
9399
94100 String result = authenticator .doAuthentication ("dummyKey" , "--param" );
95101
96102 assertEquals ("Cx error" , result );
97- verify (mockLogger ) .error (
98- eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "Cx error" )),
99- any (CxException .class )
100- );
103+ mockedCxLogger . verify (() -> CxLogger .error (
104+ eq (String .format (PluginConstants .ERROR_AUTHENTICATING_AST , "Cx error" )),
105+ any (CxException .class )
106+ ) );
101107 }
102108 }
103109
0 commit comments