Skip to content

Commit af87663

Browse files
SCANJLIB-246 Try adding test
1 parent 481a70d commit af87663

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/src/main/java/org/sonarsource/scanner/lib/internal/facade/forked/JavaRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class JavaRunner {
3737
private static final Logger LOG = LoggerFactory.getLogger(JavaRunner.class);
3838

39-
private static final String JRE_VERSION_ERROR = "The version of the custom JRE provided to the SonarScanner using the 'sonar.scanner.javaExePath' parameter is incompatible " +
39+
static final String JRE_VERSION_ERROR = "The version of the custom JRE provided to the SonarScanner using the 'sonar.scanner.javaExePath' parameter is incompatible " +
4040
"with your SonarQube target. You may need to upgrade the version of Java that executes the scanner. " +
4141
"Refer to https://docs.sonarsource.com/sonarqube-community-build/analyzing-source-code/scanners/scanner-environment/general-requirements/ for more details.";
4242

lib/src/test/java/org/sonarsource/scanner/lib/internal/facade/forked/JavaRunnerTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@
1919
*/
2020
package org.sonarsource.scanner.lib.internal.facade.forked;
2121

22+
import java.io.IOException;
2223
import java.nio.file.Paths;
2324
import java.util.List;
2425
import java.util.concurrent.ConcurrentLinkedDeque;
2526
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.condition.EnabledOnOs;
28+
import org.junit.jupiter.api.condition.OS;
2629
import org.junit.jupiter.api.extension.RegisterExtension;
2730
import org.slf4j.event.Level;
2831
import testutils.LogTester;
2932

3033
import static org.assertj.core.api.Assertions.assertThat;
3134
import static org.assertj.core.api.Assertions.assertThatThrownBy;
35+
import static org.sonarsource.scanner.lib.internal.facade.forked.JavaRunner.JRE_VERSION_ERROR;
3236

3337
class JavaRunnerTest {
3438

@@ -84,4 +88,19 @@ void execute_shouldReturnFalseWhenNonZeroExitCode() {
8488
assertThat(runner.execute(command, null, stdOut::add)).isFalse();
8589
}
8690

91+
@Test
92+
@EnabledOnOs(OS.LINUX)
93+
void execute_shouldLogUnsupportedClassVersionError() throws IOException, InterruptedException {
94+
95+
JavaRunner runner = new JavaRunner(Paths.get("java"), JreCacheHit.DISABLED);
96+
List<String> command = List.of("-xyz");
97+
98+
ProcessBuilder processBuilder = new ProcessBuilder("sh", "-c", "\">&2 echo 'UnsupportedClassVersionError'\"");
99+
Process process = processBuilder.start();
100+
101+
assertThat(runner.execute(command, "test", stdOut::add)).isFalse();
102+
103+
assertThat(logTester.logs(Level.ERROR)).contains(JRE_VERSION_ERROR);
104+
}
105+
87106
}

0 commit comments

Comments
 (0)