diff --git a/its/plugin/build.gradle.kts b/its/plugin/build.gradle.kts index 2637181c4..2934b1811 100644 --- a/its/plugin/build.gradle.kts +++ b/its/plugin/build.gradle.kts @@ -1,6 +1,7 @@ dependencies { testImplementation(testLibs.sonarlint.core) - testImplementation(testLibs.sonar.orchestrator.junit4) + testImplementation(testLibs.sonar.orchestrator.junit5) + testImplementation(testLibs.junit.engine) testImplementation(testLibs.assertj.core) testImplementation(testLibs.sonar.ws) testImplementation(libs.sonar.analyzer.commons) @@ -9,13 +10,10 @@ dependencies { sonarqube.isSkipProject = true tasks.test { + useJUnitPlatform() onlyIf { project.hasProperty("plugin") || project.hasProperty("its") } - filter { - includeTestsMatching("org.sonarsource.slang.Tests") - includeTestsMatching("org.sonarsource.slang.SonarLintTest") - } systemProperty("java.awt.headless", "true") outputs.upToDateWhen { false } } diff --git a/its/plugin/src/test/java/org/sonarsource/slang/DuplicationsTest.java b/its/plugin/src/test/java/org/sonarsource/slang/DuplicationsTest.java index e2972075f..becda2d73 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/DuplicationsTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/DuplicationsTest.java @@ -19,7 +19,7 @@ */ package org.sonarsource.slang; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/test/java/org/sonarsource/slang/ExternalReportTest.java b/its/plugin/src/test/java/org/sonarsource/slang/ExternalReportTest.java index fddf4acd5..0ea2a8007 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/ExternalReportTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/ExternalReportTest.java @@ -20,9 +20,7 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.SonarScanner; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; import org.sonarqube.ws.Issues.Issue; import org.sonarqube.ws.client.issues.SearchRequest; @@ -35,9 +33,6 @@ public class ExternalReportTest extends TestBase { private static final String BASE_DIRECTORY = "projects/externalreport/"; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); - @Test public void detekt() { final String projectKey = "detekt"; diff --git a/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java b/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java index b540538f9..1a064e6bd 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/MeasuresTest.java @@ -19,7 +19,7 @@ */ package org.sonarsource.slang; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.sonarqube.ws.Issues; import java.util.List; diff --git a/its/plugin/src/test/java/org/sonarsource/slang/SonarLintTest.java b/its/plugin/src/test/java/org/sonarsource/slang/SonarLintTest.java index 1b7a1eae5..1061b41f7 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/SonarLintTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/SonarLintTest.java @@ -19,9 +19,22 @@ */ package org.sonarsource.slang; -import com.sonar.orchestrator.junit4.OrchestratorRule; -import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder; import com.sonar.orchestrator.locator.Locators; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl; +import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile; +import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue; +import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration; +import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration; +import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine; +import org.sonarsource.sonarlint.core.commons.IssueSeverity; +import org.sonarsource.sonarlint.core.commons.Language; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -32,40 +45,27 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl; -import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile; -import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue; -import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration; -import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration; -import org.sonarsource.sonarlint.core.client.api.standalone.StandaloneSonarLintEngine; -import org.sonarsource.sonarlint.core.commons.IssueSeverity; -import org.sonarsource.sonarlint.core.commons.Language; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; public class SonarLintTest { - @ClassRule - public static TemporaryFolder temp = new TemporaryFolder(); + @TempDir + public static File temp; private static StandaloneSonarLintEngine sonarlintEngine; private static File baseDir; - @BeforeClass + @BeforeAll public static void prepare() throws Exception { // Orchestrator is used only to retrieve plugin artifacts from filesystem or maven - OrchestratorRuleBuilder orchestratorBuilder = OrchestratorRule.builderEnv(); - Tests.addLanguagePlugins(orchestratorBuilder); - OrchestratorRule orchestrator = orchestratorBuilder + OrchestratorExtensionBuilder orchestratorBuilder = OrchestratorExtension.builderEnv(); + TestsHelper.addLanguagePlugins(orchestratorBuilder); + OrchestratorExtension orchestrator = orchestratorBuilder .useDefaultAdminCredentialsForBuilds(true) - .setSonarVersion(System.getProperty(Tests.SQ_VERSION_PROPERTY, Tests.DEFAULT_SQ_VERSION)) + .setSonarVersion(System.getProperty(TestsHelper.SQ_VERSION_PROPERTY, TestsHelper.DEFAULT_SQ_VERSION)) .build(); Locators locators = orchestrator.getConfiguration().locators(); @@ -76,22 +76,22 @@ public static void prepare() throws Exception { sonarLintConfigBuilder .addEnabledLanguage(Language.KOTLIN) - .setSonarLintUserHome(temp.newFolder().toPath()) + .setSonarLintUserHome(temp.toPath()) .setLogOutput((formattedMessage, level) -> { /* Don't pollute logs */ }); StandaloneGlobalConfiguration configuration = sonarLintConfigBuilder.build(); sonarlintEngine = new StandaloneSonarLintEngineImpl(configuration); - baseDir = temp.newFolder(); + baseDir = temp; } - @AfterClass + @AfterAll public static void stop() { sonarlintEngine.stop(); } @Test - public void test_kotlin() throws Exception { + void test_kotlin() throws Exception { ClientInputFile inputFile = prepareInputFile("foo.kt", "fun foo_bar() {\n" + " if (true) { \n" + diff --git a/its/plugin/src/test/java/org/sonarsource/slang/SuppressWarningsTest.java b/its/plugin/src/test/java/org/sonarsource/slang/SuppressWarningsTest.java index e6863730f..f0204dc3b 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/SuppressWarningsTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/SuppressWarningsTest.java @@ -19,7 +19,8 @@ */ package org.sonarsource.slang; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/its/plugin/src/test/java/org/sonarsource/slang/SurefireTest.java b/its/plugin/src/test/java/org/sonarsource/slang/SurefireTest.java index 2c2da2937..5a608d099 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/SurefireTest.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/SurefireTest.java @@ -20,13 +20,14 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.MavenBuild; -import com.sonar.orchestrator.junit4.OrchestratorRule; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map; -import org.junit.ClassRule; -import org.junit.Test; + +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Measures; import static java.lang.Double.parseDouble; @@ -35,8 +36,8 @@ public class SurefireTest extends TestBase { - @ClassRule - public static final OrchestratorRule ORCHESTRATOR = Tests.ORCHESTRATOR; + @RegisterExtension + public static final OrchestratorExtension ORCHESTRATOR = TestsHelper.ORCHESTRATOR; private static final Path BASE_DIRECTORY = Paths.get("projects"); diff --git a/its/plugin/src/test/java/org/sonarsource/slang/TestBase.java b/its/plugin/src/test/java/org/sonarsource/slang/TestBase.java index 864946c20..cf6266609 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/TestBase.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/TestBase.java @@ -20,7 +20,6 @@ package org.sonarsource.slang; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit4.OrchestratorRule; import java.io.File; import java.util.Arrays; import java.util.Collections; @@ -29,7 +28,9 @@ import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nullable; -import org.junit.ClassRule; + +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Issues; import org.sonarqube.ws.Measures.ComponentWsResponse; import org.sonarqube.ws.Measures.Measure; @@ -43,8 +44,8 @@ public abstract class TestBase { - @ClassRule - public static final OrchestratorRule ORCHESTRATOR = Tests.ORCHESTRATOR; + @RegisterExtension + public static final OrchestratorExtension ORCHESTRATOR = TestsHelper.ORCHESTRATOR; protected SonarScanner getSonarScanner(String projectKey, String directoryToScan, String languageKey) { return getSonarScanner(projectKey, directoryToScan, languageKey, null); diff --git a/its/plugin/src/test/java/org/sonarsource/slang/Tests.java b/its/plugin/src/test/java/org/sonarsource/slang/TestsHelper.java similarity index 71% rename from its/plugin/src/test/java/org/sonarsource/slang/Tests.java rename to its/plugin/src/test/java/org/sonarsource/slang/TestsHelper.java index 323e784da..a49217fa2 100644 --- a/its/plugin/src/test/java/org/sonarsource/slang/Tests.java +++ b/its/plugin/src/test/java/org/sonarsource/slang/TestsHelper.java @@ -20,46 +20,37 @@ package org.sonarsource.slang; import com.sonar.orchestrator.OrchestratorBuilder; -import com.sonar.orchestrator.junit4.OrchestratorRule; -import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; + +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.MavenLocation; + import java.io.File; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.junit.ClassRule; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -@RunWith(Suite.class) -@Suite.SuiteClasses({ - DuplicationsTest.class, - ExternalReportTest.class, - MeasuresTest.class, - SuppressWarningsTest.class, - SurefireTest.class -}) -public class Tests { + +public class TestsHelper { static final String SQ_VERSION_PROPERTY = "sonar.runtimeVersion"; static final String DEFAULT_SQ_VERSION = "LATEST_RELEASE"; private static final Set LANGUAGES = new HashSet<>(Collections.singletonList("kotlin")); - @ClassRule - public static final OrchestratorRule ORCHESTRATOR; + public static final OrchestratorExtension ORCHESTRATOR; static { - OrchestratorRuleBuilder orchestratorBuilder = OrchestratorRule.builderEnv(); + OrchestratorExtensionBuilder orchestratorBuilder = OrchestratorExtension.builderEnv(); addLanguagePlugins(orchestratorBuilder); ORCHESTRATOR = orchestratorBuilder - .useDefaultAdminCredentialsForBuilds(true) - .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) - .restoreProfileAtStartup(FileLocation.of("src/test/resources/suppress-warnings-kotlin.xml")) - .restoreProfileAtStartup(FileLocation.of("src/test/resources/norule.xml")) - .build(); + .useDefaultAdminCredentialsForBuilds(true) + .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) + .restoreProfileAtStartup(FileLocation.of("src/test/resources/suppress-warnings-kotlin.xml")) + .restoreProfileAtStartup(FileLocation.of("src/test/resources/norule.xml")) + .build(); } static void addLanguagePlugins(OrchestratorBuilder builder) { diff --git a/its/ruling/build.gradle.kts b/its/ruling/build.gradle.kts index 1ad4172ab..ef5c7d7a2 100644 --- a/its/ruling/build.gradle.kts +++ b/its/ruling/build.gradle.kts @@ -4,14 +4,16 @@ plugins { } dependencies { - testImplementation(testLibs.sonar.orchestrator.junit4) + testImplementation(testLibs.sonar.orchestrator.junit5) testImplementation(testLibs.assertj.core) + testImplementation(testLibs.junit.engine) testImplementation(libs.sonar.analyzer.commons) } sonarqube.isSkipProject = true tasks.test { + useJUnitPlatform() onlyIf { project.hasProperty("its") || project.hasProperty("ruling") } diff --git a/its/ruling/src/test/java/org/sonarsource/slang/SlangRulingTest.java b/its/ruling/src/test/java/org/sonarsource/slang/SlangRulingTest.java index ca37a2518..b55383fb2 100644 --- a/its/ruling/src/test/java/org/sonarsource/slang/SlangRulingTest.java +++ b/its/ruling/src/test/java/org/sonarsource/slang/SlangRulingTest.java @@ -23,8 +23,9 @@ import com.sonar.orchestrator.build.Build; import com.sonar.orchestrator.build.GradleBuild; import com.sonar.orchestrator.build.SonarScanner; -import com.sonar.orchestrator.junit4.OrchestratorRule; -import com.sonar.orchestrator.junit4.OrchestratorRuleBuilder; + +import com.sonar.orchestrator.junit5.OrchestratorExtension; +import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder; import com.sonar.orchestrator.locator.FileLocation; import com.sonar.orchestrator.locator.Location; import com.sonar.orchestrator.locator.MavenLocation; @@ -41,9 +42,11 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIfSystemProperty; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonarsource.analyzer.commons.ProfileGenerator; @@ -57,15 +60,15 @@ public class SlangRulingTest { private static final String SQ_VERSION_PROPERTY = "sonar.runtimeVersion"; private static final String DEFAULT_SQ_VERSION = "LATEST_RELEASE"; - private static OrchestratorRule orchestrator; + private static OrchestratorExtension orchestrator; private static boolean keepSonarqubeRunning = "true".equals(System.getProperty("keepSonarqubeRunning")); private static final boolean IGNORE_EXPECTED_ISSUES_AND_REPORT_ALL = "true".equals(System.getProperty("reportAll")); private static final boolean CLEAN_PROJECT_BINARIES = "true".equals(System.getProperty("cleanProjects")); private static final Set LANGUAGES = new HashSet<>(Collections.singletonList("kotlin")); - @BeforeClass + @BeforeAll public static void setUp() { - OrchestratorRuleBuilder builder = OrchestratorRule.builderEnv() + OrchestratorExtensionBuilder builder = OrchestratorExtension.builderEnv() .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) .addPlugin(MavenLocation.of("org.sonarsource.sonar-lits-plugin", "sonar-lits-plugin", "0.11.0.2659")); @@ -334,7 +337,7 @@ private void executeBuildAndAssertDifferences(String project, Build build) th assertThat(litsDifference).isEmpty(); } - @AfterClass + @AfterAll public static void after() { if (keepSonarqubeRunning) { try { diff --git a/settings.gradle.kts b/settings.gradle.kts index db2211973..749629555 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -44,7 +44,6 @@ dependencyResolutionManagement { val analyzerCommons = version("analyzerCommons", analyzerCommonsVersionStr) val gson = version("gson", "2.10.1") val staxmate = version("staxmate", "2.4.1") - val gradleToolingApi = version("gradle-tooling-api", "7.5.1") library("gson", "com.google.code.gson", "gson").versionRef(gson) library("kotlin-compiler-embeddable", "org.jetbrains.kotlin", "kotlin-compiler-embeddable").version(kotlinVersion) @@ -96,7 +95,7 @@ dependencyResolutionManagement { library("mockk", "io.mockk", "mockk").versionRef(mockk) library("sonar-analyzer-test-commons", "org.sonarsource.analyzer-commons", "sonar-analyzer-test-commons") .versionRef(analyzerCommons) - library("sonar-orchestrator-junit4", "org.sonarsource.orchestrator", "sonar-orchestrator-junit4").versionRef(orchestrator) + library("sonar-orchestrator-junit5", "org.sonarsource.orchestrator", "sonar-orchestrator-junit5").versionRef(orchestrator) library("sonar-plugin-api-impl", "org.sonarsource.sonarqube", "sonar-plugin-api-impl").versionRef(sonarqube) library("sonar-plugin-api-test-fixtures", "org.sonarsource.api.plugin", "sonar-plugin-api-test-fixtures") .version(sonarPluginApi)