aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2024-10-11 15:20:42 +0200
committersonartech <sonartech@sonarsource.com>2024-10-11 20:02:44 +0000
commitce2e686a3e269f937ffb51635928cd1a597b2d07 (patch)
tree5c7e1e7f98635d356c4784a6c4e6e57eb5fe8693 /sonar-scanner-protocol
parent6a29a994884242a240f7385957903bb278504e17 (diff)
downloadsonarqube-ce2e686a3e269f937ffb51635928cd1a597b2d07.tar.gz
sonarqube-ce2e686a3e269f937ffb51635928cd1a597b2d07.zip
SONAR-23327 Update tests to Junit5
Diffstat (limited to 'sonar-scanner-protocol')
-rw-r--r--sonar-scanner-protocol/build.gradle9
-rw-r--r--sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java53
-rw-r--r--sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java51
3 files changed, 58 insertions, 55 deletions
diff --git a/sonar-scanner-protocol/build.gradle b/sonar-scanner-protocol/build.gradle
index f0c1546a5d7..43ea08b6c59 100644
--- a/sonar-scanner-protocol/build.gradle
+++ b/sonar-scanner-protocol/build.gradle
@@ -17,7 +17,16 @@ dependencies {
testImplementation 'com.google.guava:guava'
testImplementation 'junit:junit'
+ testImplementation 'org.junit.jupiter:junit-jupiter-api'
+ testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.assertj:assertj-core'
+
+ testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+ testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
+}
+
+test {
+ useJUnitPlatform()
}
//create a single Jar with all dependencies
diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
index 9c7ada548b3..e59d2e00798 100644
--- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
+++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/FileStructureTest.java
@@ -22,45 +22,40 @@ package org.sonar.scanner.protocol.output;
import java.io.File;
import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class FileStructureTest {
+class FileStructureTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ public File temp;
@Test
- public void fail_if_dir_does_not_exist() throws Exception {
- File dir = temp.newFolder();
+ void fail_if_dir_does_not_exist() {
+ File dir = temp;
FileUtils.deleteQuietly(dir);
- try {
- new FileStructure(dir);
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageContaining("Directory of analysis report does not exist");
- }
+
+ assertThatThrownBy(() -> new FileStructure(dir))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("Directory of analysis report does not exist");
}
@Test
- public void fail_if_invalid_dir() throws Exception {
+ void fail_if_invalid_dir() {
// not a dir but a file
- File dir = temp.newFile();
- try {
- new FileStructure(dir);
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageContaining("Directory of analysis report does not exist");
- }
+ File dir = new File(temp, "newFile");
+
+ assertThatThrownBy(() -> new FileStructure(dir))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining("Directory of analysis report does not exist");
}
@Test
- public void locate_files() throws Exception {
- File dir = temp.newFolder();
+ void locate_files() throws Exception {
+ File dir = temp;
FileUtils.write(new File(dir, "metadata.pb"), "metadata content", Charset.defaultCharset());
FileUtils.write(new File(dir, "issues-3.pb"), "external issues of component 3", Charset.defaultCharset());
FileUtils.write(new File(dir, "external-issues-3.pb"), "issues of component 3", Charset.defaultCharset());
@@ -76,8 +71,8 @@ public class FileStructureTest {
}
@Test
- public void contextProperties_file() throws Exception {
- File dir = temp.newFolder();
+ void contextProperties_file() throws Exception {
+ File dir = temp;
File file = new File(dir, "context-props.pb");
FileUtils.write(file, "content", Charset.defaultCharset());
@@ -86,8 +81,8 @@ public class FileStructureTest {
}
@Test
- public void telemetryFile_hasTheCorrectName() throws Exception {
- File dir = temp.newFolder();
+ void telemetryFile_hasTheCorrectName() throws Exception {
+ File dir = temp;
File file = new File(dir, "telemetry-entries.pb");
FileUtils.write(file, "content", Charset.defaultCharset());
diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
index 4b89c9a3db5..1dd80d25714 100644
--- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
+++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java
@@ -23,10 +23,9 @@ import com.google.common.collect.Iterators;
import java.io.File;
import java.time.Instant;
import java.util.List;
-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.io.TempDir;
import org.sonar.core.util.CloseableIterator;
import org.sonar.core.util.Protobuf;
import org.sonar.scanner.protocol.Constants;
@@ -36,19 +35,19 @@ import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.Hi
import static org.assertj.core.api.Assertions.assertThat;
-public class ScannerReportWriterTest {
+class ScannerReportWriterTest {
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ public File temp;
private ScannerReportWriter underTest;
- @Before
- public void setUp() throws Exception {
- underTest = new ScannerReportWriter(new FileStructure(temp.newFolder()));
+ @BeforeEach
+ void setUp() {
+ underTest = new ScannerReportWriter(new FileStructure(temp));
}
@Test
- public void write_metadata() {
+ void write_metadata() {
ScannerReport.Metadata.Builder metadata = ScannerReport.Metadata.newBuilder()
.setAnalysisDate(15000000L)
.setProjectKey("PROJECT_A")
@@ -62,7 +61,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_component() {
+ void write_component() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse();
@@ -88,7 +87,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_issues() {
+ void write_issues() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();
@@ -108,7 +107,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_external_issues() {
+ void write_external_issues() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.EXTERNAL_ISSUES, 1)).isFalse();
@@ -128,7 +127,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_adhoc_rule() {
+ void write_adhoc_rule() {
// write data
ScannerReport.AdHocRule rule = ScannerReport.AdHocRule.newBuilder()
@@ -149,7 +148,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_cve() {
+ void write_cve() {
// write data
ScannerReport.Cve cve = ScannerReport.Cve.newBuilder()
@@ -173,7 +172,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_changed_lines() {
+ void write_changed_lines() {
assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isFalse();
ScannerReport.ChangedLines changedLines = ScannerReport.ChangedLines.newBuilder()
@@ -190,7 +189,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_measures() {
+ void write_measures() {
assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse();
ScannerReport.Measure measure = ScannerReport.Measure.newBuilder()
@@ -208,7 +207,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_scm() {
+ void write_scm() {
assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isFalse();
ScannerReport.Changesets scm = ScannerReport.Changesets.newBuilder()
@@ -233,7 +232,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_duplications() {
+ void write_duplications() {
assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isFalse();
ScannerReport.Duplication duplication = ScannerReport.Duplication.newBuilder()
@@ -262,7 +261,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_duplication_blocks() {
+ void write_duplication_blocks() {
assertThat(underTest.hasComponentData(FileStructure.Domain.CPD_TEXT_BLOCKS, 1)).isFalse();
ScannerReport.CpdTextBlock duplicationBlock = ScannerReport.CpdTextBlock.newBuilder()
@@ -288,7 +287,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_symbols() {
+ void write_symbols() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.SYMBOLS, 1)).isFalse();
@@ -320,7 +319,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_syntax_highlighting() {
+ void write_syntax_highlighting() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isFalse();
@@ -337,7 +336,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_line_significant_code() {
+ void write_line_significant_code() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, 1)).isFalse();
@@ -352,7 +351,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_coverage() {
+ void write_coverage() {
// no data yet
assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isFalse();
@@ -368,7 +367,7 @@ public class ScannerReportWriterTest {
}
@Test
- public void write_telemetry() {
+ void write_telemetry() {
List<ScannerReport.TelemetryEntry> input = List.of(
ScannerReport.TelemetryEntry.newBuilder()