50
50
import org .sonatype .plexus .components .sec .dispatcher .SecDispatcher ;
51
51
52
52
import static org .assertj .core .api .Assertions .assertThat ;
53
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
53
54
import static org .junit .Assert .assertThrows ;
54
55
import static org .mockito .ArgumentMatchers .any ;
55
56
import static org .mockito .ArgumentMatchers .contains ;
@@ -123,6 +124,8 @@ void setUp()
123
124
124
125
when (scannerEngineBootstrapResult .getEngineFacade ()).thenReturn (scannerEngineFacade );
125
126
when (scannerEngineBootstrapper .bootstrap ()).thenReturn (scannerEngineBootstrapResult );
127
+ when (scannerEngineBootstrapResult .isSuccessful ()).thenReturn (true );
128
+ when (scannerEngineFacade .analyze (any ())).thenReturn (true );
126
129
scannerBootstrapper = new ScannerBootstrapper (log , session , scannerEngineBootstrapper , mavenProjectConverter , new PropertyDecryptor (log , securityDispatcher ));
127
130
}
128
131
@@ -148,6 +151,29 @@ void testSQ56() throws MojoExecutionException {
148
151
verifyCommonCalls ();
149
152
}
150
153
154
+ @ Test
155
+ void when_ScannerEngineBootstrapper_is_not_successful_getEngineFacade_should_not_be_called () {
156
+ when (scannerEngineBootstrapResult .isSuccessful ()).thenReturn (false );
157
+ when (scannerEngineBootstrapResult .getEngineFacade ()).thenThrow (new IllegalAccessError ("Should not be called" ));
158
+ when (scannerEngineFacade .isSonarCloud ()).thenReturn (false );
159
+ when (scannerEngineFacade .getServerVersion ()).thenReturn ("5.6" );
160
+
161
+ assertThatThrownBy ( () -> scannerBootstrapper .execute ())
162
+ .isInstanceOf (MojoExecutionException .class )
163
+ .hasMessage ("The scanner boostrapping has failed! See the logs for more details." );
164
+ }
165
+
166
+ @ Test
167
+ void throw_an_exception_when_analyze_fail () {
168
+ when (scannerEngineFacade .analyze (any ())).thenReturn (false );
169
+ when (scannerEngineFacade .isSonarCloud ()).thenReturn (false );
170
+ when (scannerEngineFacade .getServerVersion ()).thenReturn ("5.6" );
171
+
172
+ assertThatThrownBy ( () -> scannerBootstrapper .execute ())
173
+ .isInstanceOf (MojoExecutionException .class )
174
+ .hasMessage ("The scanner analysis has failed! See the logs for more details." );
175
+ }
176
+
151
177
@ Test
152
178
void testVersionComparisonWithBuildNumber () throws MojoExecutionException {
153
179
when (scannerEngineFacade .isSonarCloud ()).thenReturn (false );
0 commit comments