Skip to content

Commit 0ecc483

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

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

+1-1
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

+23
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
import java.util.List;
2424
import java.util.concurrent.ConcurrentLinkedDeque;
2525
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.condition.EnabledOnOs;
27+
import org.junit.jupiter.api.condition.OS;
2628
import org.junit.jupiter.api.extension.RegisterExtension;
2729
import org.slf4j.event.Level;
2830
import testutils.LogTester;
2931

3032
import static org.assertj.core.api.Assertions.assertThat;
3133
import static org.assertj.core.api.Assertions.assertThatThrownBy;
34+
import static org.sonarsource.scanner.lib.internal.facade.forked.JavaRunner.JRE_VERSION_ERROR;
3235

3336
class JavaRunnerTest {
3437

@@ -84,4 +87,24 @@ void execute_shouldReturnFalseWhenNonZeroExitCode() {
8487
assertThat(runner.execute(command, null, stdOut::add)).isFalse();
8588
}
8689

90+
@Test
91+
@EnabledOnOs(OS.WINDOWS)
92+
void execute_shouldLogUnsupportedClassVersionError_whenOsIsWindows() {
93+
JavaRunner runner = new JavaRunner(Paths.get("cmd.exe"), JreCacheHit.DISABLED);
94+
List<String> command = List.of("/c", "echo UnsupportedClassVersionError 1>&2");
95+
96+
assertThat(runner.execute(command, null, stdOut::add)).isTrue();
97+
assertThat(logTester.logs(Level.ERROR)).contains(JRE_VERSION_ERROR);
98+
}
99+
100+
@Test
101+
@EnabledOnOs(OS.LINUX)
102+
void execute_shouldLogUnsupportedClassVersionError_whenOsIsLinux() {
103+
JavaRunner runner = new JavaRunner(Paths.get("sh"), JreCacheHit.DISABLED);
104+
List<String> command = List.of("-c", " >&2 echo UnsupportedClassVersionError");
105+
106+
assertThat(runner.execute(command, null, stdOut::add)).isTrue();
107+
assertThat(logTester.logs(Level.ERROR)).contains(JRE_VERSION_ERROR);
108+
}
109+
87110
}

0 commit comments

Comments
 (0)