Skip to content

Commit

Permalink
Move duplicated expected String into constants
Browse files Browse the repository at this point in the history
  • Loading branch information
alban-auzeill committed Oct 30, 2024
1 parent e9c8201 commit 0f5418f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions its/src/test/java/com/sonar/maven/it/suite/BootstrapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@

class BootstrapTest extends AbstractMavenTest {

private static final String EFFECTIVE_JRE_PROVISIONING_LOG = "JRE provisioning:";
private static final String COMMUNICATING_WITH_SONARQUBE = "Communicating with SonarQube Server";
private static final String STARTING_SCANNER_ENGINE = "Starting SonarScanner Engine";
private static final String SKIPPING_ANALYSIS = "Skipping analysis";
public static final String JRE_PROVISIONING_IS_DISABLED = "JRE provisioning is disabled";
public static final String USING_CONFIGURED_JRE = "Using the configured java executable";

@Test
void test_unsupported_platform() {
String unsupportedOS = "unsupportedOS";
Expand Down Expand Up @@ -70,8 +77,8 @@ void test_bootstrapping_with_sonar_skip_in_pom_xml() {
.setGoals(sonarGoal());
BuildResult result = executeBuildAndValidateWithoutCE(build);
assertThat(result.getLogs())
.contains("Skipping analysis")
.doesNotContain("JRE provisioning:", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(SKIPPING_ANALYSIS)
.doesNotContain(EFFECTIVE_JRE_PROVISIONING_LOG, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
}

@Test
Expand All @@ -84,8 +91,8 @@ void test_bootstrapping_with_sonar_skip_in_system_property() {
.setGoals(sonarGoal());
BuildResult result = executeBuildAndValidateWithoutCE(build);
assertThat(result.getLogs())
.contains("Skipping analysis")
.doesNotContain("JRE provisioning:", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(SKIPPING_ANALYSIS)
.doesNotContain(EFFECTIVE_JRE_PROVISIONING_LOG, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
}

@Test
Expand All @@ -98,8 +105,8 @@ void test_bootstrapping_with_sonar_skip_in_plugin_configuration() {
.setGoals(sonarGoal());
BuildResult result = executeBuildAndValidateWithoutCE(build);
assertThat(result.getLogs())
.contains("Skipping analysis")
.doesNotContain("JRE provisioning:", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(SKIPPING_ANALYSIS)
.doesNotContain(EFFECTIVE_JRE_PROVISIONING_LOG, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
}

@Test
Expand All @@ -113,10 +120,10 @@ void test_bootstrapping_that_skip_the_JRE_provisioning() throws IOException {
.setGoals(sonarGoal());
BuildResult result = executeBuildAndValidateWithCE(build);
assertThat(result.getLogs())
.doesNotContain("JRE provisioning:");
.doesNotContain(EFFECTIVE_JRE_PROVISIONING_LOG);
if (isSonarQubeSupportsJREProvisioning()) {
assertThat(result.getLogs())
.contains("JRE provisioning is disabled", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(JRE_PROVISIONING_IS_DISABLED, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
}
Path propertiesFile = ItUtils.locateProjectDir(projectName).toPath().resolve("target/sonar/dumpSensor.system.properties");
Properties props = new Properties();
Expand All @@ -136,10 +143,10 @@ void test_bootstrapping_that_use_the_provided_JRE_instead_of_downloading_a_JRE()
.setGoals(sonarGoal());
BuildResult result = executeBuildAndValidateWithCE(build);
assertThat(result.getLogs())
.doesNotContain("JRE provisioning:", "JRE provisioning is disabled");
.doesNotContain(EFFECTIVE_JRE_PROVISIONING_LOG, JRE_PROVISIONING_IS_DISABLED);
if (isSonarQubeSupportsJREProvisioning()) {
assertThat(result.getLogs())
.contains("Using the configured java executable", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(USING_CONFIGURED_JRE, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
}
Path propertiesFile = ItUtils.locateProjectDir(projectName).toPath().resolve("target/sonar/dumpSensor.system.properties");
Properties props = new Properties();
Expand Down Expand Up @@ -236,7 +243,7 @@ void test_supported_arch_to_assert_jre_used() throws IOException {
softly.assertThat(props.getProperty("http.proxyUser")).isEqualTo("my-custom-user-from-system-properties");

softly.assertThat(result.getLogs())
.contains("JRE provisioning:", "Communicating with SonarQube Server", "Starting SonarScanner Engine");
.contains(EFFECTIVE_JRE_PROVISIONING_LOG, COMMUNICATING_WITH_SONARQUBE, STARTING_SCANNER_ENGINE);
} else {
//we test that we are using the system JRE
javaHomeAssertion
Expand Down

0 comments on commit 0f5418f

Please sign in to comment.