Skip to content

Commit

Permalink
improve after review
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan-serandour committed Oct 29, 2024
1 parent 926e982 commit 1061e70
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions its/src/test/java/com/sonar/maven/it/suite/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Properties;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand Down Expand Up @@ -121,23 +122,30 @@ void setJavaVersionProperties() throws IOException {
}

@Test
void extractJdkHomeFromJre() throws IOException {
void whenPropertyJavaHomeExistsThenItIsUsedAsDefaultValue() throws IOException {
//verify that property java home exists, it may not be pointing to a jdk
if (!System.getProperties().containsKey("java.home")
&& !System.getenv().containsKey("JAVA_HOME")) {
return;
}


File outputProps = temp.resolve("out.properties").toFile();
outputProps.createNewFile();

File pom = ItUtils.locateProjectPom("jdkHome/extractFromJre");

MavenBuild build = MavenBuild.create(pom)
.setGoals(sonarGoal())
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
executeBuildAndValidateWithoutCE(build);

Properties props = getProps(outputProps);
Object value = props.getOrDefault("sonar.java.jdkHome", "");
if (value instanceof String) {
assertThat((String) value).isNotEmpty();
}
String jdkHome = props.getProperty("sonar.java.jdkHome");
//the jdk is not configured in the project, so default value should be used
assertThat(jdkHome).isIn(Arrays.asList(System.getProperty("java.home"), System.getenv().get("JAVA_HOME")));
}


@Test
void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
File outputProps = temp.resolve("out.properties").toFile();
Expand Down

0 comments on commit 1061e70

Please sign in to comment.