Skip to content

Commit

Permalink
add new integration test to check that sonar.java.jdkHome has default…
Browse files Browse the repository at this point in the history
… value even without configuration from user
  • Loading branch information
erwan-serandour committed Oct 28, 2024
1 parent 52c4e6d commit c407e62
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions its/projects/jdkHome/extractFromJre/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sonarsource.it.samples</groupId>
<artifactId>extract-jre</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Sonar :: Integration Tests :: Extract Jre</name>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sample;

public class Sample {

public Sample(int i) {
int j = i++;
}

public String myMethod() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sample;

import org.junit.Test;

public class SampleTest {

@Test
public void test() {
new Sample(1).myMethod();
}

}
19 changes: 19 additions & 0 deletions its/src/test/java/com/sonar/maven/it/suite/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ void setJavaVersionProperties() throws IOException {
entry("sonar.java.target", "1.8"));
}

@Test
void extractJdkHomeFromJre() throws IOException {
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();
}
}

@Test
void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
File outputProps = temp.resolve("out.properties").toFile();
Expand All @@ -136,6 +154,7 @@ void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
assertThat(props).contains(entry("sonar.java.jdkHome", expected));
}


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

0 comments on commit c407e62

Please sign in to comment.