aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-02-22 15:15:56 +0100
committersonartech <sonartech@sonarsource.com>2024-02-22 20:02:53 +0000
commit02ba3396555695a7577f23486b1e4c0b3c67b978 (patch)
tree8156e6b229b4e4f130cfcdb60e11480055a1ef13 /sonar-scanner-engine
parentc3503992fbe7d16e36f2fd60792d45226dfce7ee (diff)
downloadsonarqube-02ba3396555695a7577f23486b1e4c0b3c67b978.tar.gz
sonarqube-02ba3396555695a7577f23486b1e4c0b3c67b978.zip
SONAR-21643 Convert some IT tests to Junit 5 (#10672)
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java16
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/BranchMediumIT.java38
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumIT.java26
-rw-r--r--sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumIT.java64
4 files changed, 79 insertions, 65 deletions
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
index 41d49b205e0..59eb6290e79 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
@@ -40,6 +40,9 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.Priority;
import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
+import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.rules.ExternalResource;
import org.sonar.api.Plugin;
import org.sonar.api.SonarEdition;
@@ -88,7 +91,7 @@ import static java.util.Collections.emptySet;
/**
* Main utility class for writing scanner medium tests.
*/
-public class ScannerMediumTester extends ExternalResource {
+public class ScannerMediumTester extends ExternalResource implements BeforeTestExecutionCallback, AfterTestExecutionCallback {
private static Path userHome = null;
private final Map<String, String> globalProperties = new HashMap<>();
@@ -246,6 +249,16 @@ public class ScannerMediumTester extends ExternalResource {
}
@Override
+ public void afterTestExecution(ExtensionContext extensionContext) {
+ after();
+ }
+
+ @Override
+ public void beforeTestExecution(ExtensionContext extensionContext) {
+ before();
+ }
+
+ @Override
protected void before() {
try {
createWorkingDirs();
@@ -267,6 +280,7 @@ public class ScannerMediumTester extends ExternalResource {
}
}
+
public AnalysisBuilder newAnalysis() {
return new AnalysisBuilder(this);
}
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/BranchMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/BranchMediumIT.java
index 4fad517b2fa..31f2bcbfef0 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/BranchMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/BranchMediumIT.java
@@ -27,15 +27,15 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.FileMetadata;
import org.sonar.api.notifications.AnalysisWarnings;
-import org.sonar.api.testfixtures.log.LogTester;
+import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.scanner.mediumtest.AnalysisResult;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.protocol.output.ScannerReport;
@@ -48,31 +48,31 @@ import org.sonarqube.ws.NewCodePeriods;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-public class BranchMediumIT {
+class BranchMediumIT {
private static final String PROJECT_KEY = "sample";
private static final String FILE_PATH = "HelloJava.xoo";
private static final String FILE_CONTENT = "xoooo";
- public static final String ONE_ISSUE_PER_LINE_IS_RESTRICTED_TO_CHANGED_FILES_ONLY = "Sensor One Issue Per Line is restricted to changed files only";
+ private static final String ONE_ISSUE_PER_LINE_IS_RESTRICTED_TO_CHANGED_FILES_ONLY = "Sensor One Issue Per Line is restricted to changed files only";
private File baseDir;
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ public File temp;
- @Rule
- public LogTester logTester = new LogTester();
+ @RegisterExtension
+ public LogTesterJUnit5 logTester = new LogTesterJUnit5();
- @Rule
+ @RegisterExtension
public ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
.addRules(new XooRulesDefinition())
.addActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "OneIssuePerLine.internal", "xoo");
- @Before
- public void prepare() throws IOException {
+ @BeforeEach
+ void prepare() throws IOException {
logTester.setLevel(Level.DEBUG);
- baseDir = temp.newFolder();
+ baseDir = temp;
Path filepath = baseDir.toPath().resolve(FILE_PATH);
Files.write(filepath, FILE_CONTENT.getBytes());
@@ -87,7 +87,7 @@ public class BranchMediumIT {
}
@Test
- public void should_not_skip_report_for_unchanged_files_in_pr() {
+ void should_not_skip_report_for_unchanged_files_in_pr() {
// sanity check, normally report gets generated
AnalysisResult result = getResult(tester);
final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
@@ -108,7 +108,7 @@ public class BranchMediumIT {
}
@Test
- public void shouldSkipSensorForUnchangedFilesOnPr() {
+ void shouldSkipSensorForUnchangedFilesOnPr() {
AnalysisResult result = getResult(tester
.setBranchName("myBranch")
.setBranchTarget("main")
@@ -122,7 +122,7 @@ public class BranchMediumIT {
}
@Test
- public void shouldNotSkipSensorForUnchangedFilesOnBranch() throws Exception {
+ void shouldNotSkipSensorForUnchangedFilesOnBranch() throws Exception {
AnalysisResult result = getResult(tester
.setBranchName("myBranch")
.setBranchTarget("main")
@@ -136,7 +136,7 @@ public class BranchMediumIT {
}
@Test
- public void verify_metadata() {
+ void verify_metadata() {
String branchName = "feature";
String branchTarget = "branch-1.x";
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumIT.java
index 87612bac620..a8ccd819f7d 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumIT.java
@@ -24,10 +24,10 @@ import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
import org.sonar.api.utils.MessageException;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.xoo.XooPlugin;
@@ -35,13 +35,13 @@ import org.sonar.xoo.rule.XooRulesDefinition;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class DeprecatedBranchMediumIT {
+class DeprecatedBranchMediumIT {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ private File temp;
- @Rule
- public ScannerMediumTester tester = new ScannerMediumTester()
+ @RegisterExtension
+ private final ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("xoo", new XooPlugin())
.addRules(new XooRulesDefinition())
// active a rule just to be sure that xoo files are published
@@ -52,9 +52,9 @@ public class DeprecatedBranchMediumIT {
private Map<String, String> commonProps;
- @Before
- public void prepare() {
- baseDir = temp.getRoot();
+ @BeforeEach
+ void prepare() {
+ baseDir = temp;
commonProps = ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
@@ -68,7 +68,7 @@ public class DeprecatedBranchMediumIT {
}
@Test
- public void scanProjectWithBranch() throws IOException {
+ void scanProjectWithBranch() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumIT.java
index 5024b3fea95..2d0c1852d2c 100644
--- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumIT.java
+++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/coverage/CoverageMediumIT.java
@@ -24,13 +24,13 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.api.io.TempDir;
import org.slf4j.event.Level;
import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.testfixtures.log.LogTester;
+import org.sonar.api.testfixtures.log.LogTesterJUnit5;
import org.sonar.scanner.mediumtest.AnalysisResult;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
import org.sonar.scanner.protocol.output.ScannerReport;
@@ -39,28 +39,28 @@ import org.sonar.xoo.XooPlugin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.tuple;
-public class CoverageMediumIT {
+class CoverageMediumIT {
- @Rule
- public LogTester logTester = new LogTester();
+ @RegisterExtension
+ private final LogTesterJUnit5 logTester = new LogTesterJUnit5();
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ private File temp;
- @Rule
- public ScannerMediumTester tester = new ScannerMediumTester()
+ @RegisterExtension
+ private final ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way");
- @Before
- public void prepare() throws IOException {
+ @BeforeEach
+ void prepare() throws IOException {
logTester.setLevel(Level.DEBUG);
}
@Test
- public void singleReport() throws IOException {
+ void singleReport() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -84,9 +84,9 @@ public class CoverageMediumIT {
}
@Test
- public void twoReports() throws IOException {
+ void twoReports() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -113,9 +113,9 @@ public class CoverageMediumIT {
}
@Test
- public void exclusionsForSimpleProject() throws IOException {
+ void exclusionsForSimpleProject() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -138,9 +138,9 @@ public class CoverageMediumIT {
}
@Test
- public void warn_user_for_outdated_inherited_scanner_side_exclusions_for_multi_module_project() throws IOException {
+ void warn_user_for_outdated_inherited_scanner_side_exclusions_for_multi_module_project() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
@@ -179,9 +179,9 @@ public class CoverageMediumIT {
}
@Test
- public void module_level_exclusions_override_parent_for_multi_module_project() throws IOException {
+ void module_level_exclusions_override_parent_for_multi_module_project() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
@@ -218,9 +218,9 @@ public class CoverageMediumIT {
}
@Test
- public void warn_user_for_outdated_server_side_exclusions_for_multi_module_project() throws IOException {
+ void warn_user_for_outdated_server_side_exclusions_for_multi_module_project() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
@@ -260,9 +260,9 @@ public class CoverageMediumIT {
}
@Test
- public void fallbackOnExecutableLines() throws IOException {
+ void fallbackOnExecutableLines() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -296,9 +296,9 @@ public class CoverageMediumIT {
// SONAR-11641
@Test
- public void dontFallbackOnExecutableLinesIfNoCoverageSaved() throws IOException {
+ void dontFallbackOnExecutableLinesIfNoCoverageSaved() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -327,9 +327,9 @@ public class CoverageMediumIT {
// SONAR-9557
@Test
- public void exclusionsAndForceToZeroOnModules() throws IOException {
+ void exclusionsAndForceToZeroOnModules() throws IOException {
- File baseDir = temp.getRoot();
+ File baseDir = temp;
File srcDir = new File(baseDir, "module1/src");
srcDir.mkdir();