3737import org .sonarsource .scanner .lib .internal .http .ServerConnection ;
3838
3939import static org .assertj .core .api .Assertions .assertThat ;
40+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
4041import static org .assertj .core .api .Assertions .entry ;
4142import static org .junit .jupiter .api .Assertions .assertThrows ;
4243import static org .mockito .ArgumentMatchers .any ;
@@ -107,7 +108,8 @@ void should_use_old_bootstrapping_with_sonarqube_10_5() throws Exception {
107108
108109 ScannerEngineBootstrapper bootstrapper = new ScannerEngineBootstrapper ("Gradle" , "3.1" , system , serverConnection ,
109110 launcherFactory , scannerEngineLauncherFactory );
110- when (serverConnection .callRestApi ("/analysis/version" )).thenReturn ("10.5" );
111+ when (serverConnection .callRestApi ("/analysis/version" )).thenThrow (new IOException ("404 Not found" ));
112+ when (serverConnection .callWebApi ("/api/server/version" )).thenReturn ("10.5" );
111113
112114 try (var scannerEngineFacade = bootstrapper .setBootstrapProperty (ScannerProperties .HOST_URL , "http://localhost" ).bootstrap ()) {
113115 verify (launcherFactory ).createLauncher (eq (serverConnection ), any (FileCache .class ));
@@ -116,6 +118,26 @@ void should_use_old_bootstrapping_with_sonarqube_10_5() throws Exception {
116118 }
117119 }
118120
121+ @ Test
122+ void should_preserve_both_exceptions_when_checking_version () throws Exception {
123+ IsolatedLauncherFactory launcherFactory = mock (IsolatedLauncherFactory .class );
124+ when (launcherFactory .createLauncher (eq (serverConnection ), any (FileCache .class )))
125+ .thenReturn (mock (IsolatedLauncherFactory .IsolatedLauncherAndClassloader .class ));
126+
127+ ScannerEngineBootstrapper bootstrapper = new ScannerEngineBootstrapper ("Gradle" , "3.1" , system , serverConnection ,
128+ launcherFactory , scannerEngineLauncherFactory );
129+ when (serverConnection .callRestApi ("/analysis/version" )).thenThrow (new IOException ("404 Not found" ));
130+ when (serverConnection .callWebApi ("/api/server/version" )).thenThrow (new IOException ("400 Server Error" ));
131+
132+ assertThatThrownBy (() -> {
133+ try (var ignored = bootstrapper .setBootstrapProperty (ScannerProperties .HOST_URL , "http://localhost" ).bootstrap ()) {
134+ // Should throw
135+ }
136+ })
137+ .hasMessage ("Failed to get server version" )
138+ .hasStackTraceContaining ("400 Server Error" , "404 Not found" );
139+ }
140+
119141 @ Test
120142 void should_launch_in_simulation_mode () throws Exception {
121143 try (var scannerEngine = underTest
0 commit comments