aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorDejan Milisavljevic <130993898+dejan-milisavljevic-sonarsource@users.noreply.github.com>2024-02-15 16:46:48 +0100
committersonartech <sonartech@sonarsource.com>2024-02-15 20:02:34 +0000
commit354bbb2091038a18d621799bc70b06f6376e63ea (patch)
tree46d6fb4164affab487afed40d487b9dd3ae0e815 /sonar-scanner-engine/src/test/java/org/sonar/scanner
parentafa1e65cfbe2f17f39ba73e1fe2dd2a543c5bf9a (diff)
downloadsonarqube-354bbb2091038a18d621799bc70b06f6376e63ea.tar.gz
sonarqube-354bbb2091038a18d621799bc70b06f6376e63ea.zip
SONAR-20958 Improve error message for startColumn on empty line (#10628)
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java27
1 files changed, 26 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java
index be0d139b4cd..549a8517a16 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ExternalIssueImporterTest.java
@@ -71,7 +71,7 @@ public class ExternalIssueImporterTest {
context = SensorContextTester.create(baseDir);
sourceFile = new TestInputFileBuilder("foo", "src/Foo.java")
.setModuleBaseDir(baseDir.toPath())
- .initMetadata("the first line\nthe second line")
+ .initMetadata("the first line\nthe second line\n\n")
.setCharset(UTF_8)
.setLanguage("java")
.build();
@@ -174,6 +174,18 @@ public class ExternalIssueImporterTest {
}
@Test
+ public void execute_whenNewFormatWithStartColumnOnEmptyLine_shouldThrowException() {
+ ExternalIssueReport.TextRange input = new ExternalIssueReport.TextRange();
+ input.startLine = 3;
+ input.startColumn = 0;
+
+ ExternalIssueReport.Issue issue = newIssue(input);
+ assertThatThrownBy(() -> runOn(issue))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("A 'startColumn' [line=3, lineOffset=0] cannot be provided when the line is empty");
+ }
+
+ @Test
public void execute_whenNewFormatContainsNonExistentCleanCodeAttribute_shouldThrowException() {
ExternalIssueReport report = new ExternalIssueReport();
ExternalIssueReport.Rule rule = createRule("not_existent_attribute", MAINTAINABILITY.name(), HIGH.name());
@@ -304,6 +316,19 @@ public class ExternalIssueImporterTest {
assertThat(got.end().lineOffset()).isEqualTo(sourceFile.selectLine(input.endLine).end().lineOffset());
}
+ @Test
+ public void execute_whenDeprecatedFormatWithStartColumnOnEmptyLine_shouldThrowException() {
+ ExternalIssueReport.TextRange input = new ExternalIssueReport.TextRange();
+ input.startLine = 3;
+ input.startColumn = 0;
+
+ ExternalIssueReport.Issue issue = newIssue(input);
+ assertThatThrownBy(() -> runOnDeprecatedFormat(issue))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("A 'startColumn' [line=3, lineOffset=0] cannot be provided when the line is empty");
+ }
+
+
private static ExternalIssueReport.Rule createRule() {
return createRule(RULE_ATTRIBUTE.name(), SECURITY.name(), HIGH.name());
}