use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class DefaultJavaFileScannerContextTest method report_issue_with_message.
@Test
void report_issue_with_message() {
AnalyzerMessage message = context.createAnalyzerMessage(CHECK, compilationUnitTree, "msg");
context.reportIssue(message);
assertThat(reportedMessage.getMessage()).isEqualTo("msg");
assertThat(reportedMessage.getCost()).isNull();
assertThat(reportedMessage.flows).isEmpty();
assertMessagePosition(reportedMessage, 1, 0, 6, 1);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaFileScannerContextForTestsTest method reportIssue_on_tree_with_secondaries.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void reportIssue_on_tree_with_secondaries(boolean withSecondariesAndCost) {
JavaFileScannerContext.Location location1 = new JavaFileScannerContext.Location("secondary message on }", classA.closeBraceToken());
JavaFileScannerContext.Location location2 = new JavaFileScannerContext.Location("secondary message on {", classA.openBraceToken());
List<JavaFileScannerContext.Location> secondaries = withSecondariesAndCost ? Arrays.asList(location1, location2) : Collections.emptyList();
Integer cost = withSecondariesAndCost ? 42 : null;
context.reportIssue(CHECK, classA, "issue on A", secondaries, cost);
Set<AnalyzerMessage> issues = context.getIssues();
assertThat(issues).hasSize(1);
AnalyzerMessage issue = issues.iterator().next();
assertThat(issue.getCheck()).isInstanceOf(DummyRule.class);
assertThat(issue.getMessage()).isEqualTo("issue on A");
assertThat(issue.getInputComponent()).isEqualTo(inputFile);
assertThat(issue.getLine()).isEqualTo(2);
if (withSecondariesAndCost) {
assertThat(issue.getCost()).isEqualTo(42);
assertThat(issue.flows).hasSize(2).allMatch(secondary -> secondary.size() == 1);
AnalyzerMessage secondary = issue.flows.get(1).get(0);
assertThat(secondary.getMessage()).isEqualTo("secondary message on {");
} else {
assertThat(issue.getCost()).isNull();
assertThat(issue.flows).isEmpty();
}
assertPosition(issue.primaryLocation(), 2, 0, 2, 10);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaFileScannerContextForTestsTest method reportIssue_between_trees_with_flows.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void reportIssue_between_trees_with_flows(boolean withFlowsAndCost) {
JavaFileScannerContext.Location location1 = new JavaFileScannerContext.Location("secondary message on }", classA.closeBraceToken());
JavaFileScannerContext.Location location2 = new JavaFileScannerContext.Location("secondary message on {", classA.openBraceToken());
Iterable<List<JavaFileScannerContext.Location>> flows = withFlowsAndCost ? Collections.singletonList(Arrays.asList(location1, location2)) : Collections.emptyList();
Integer cost = withFlowsAndCost ? 42 : null;
context.reportIssueWithFlow(CHECK, classA, "issue on A", flows, cost);
Set<AnalyzerMessage> issues = context.getIssues();
assertThat(issues).hasSize(1);
AnalyzerMessage issue = issues.iterator().next();
assertThat(issue.getCheck()).isInstanceOf(DummyRule.class);
assertThat(issue.getMessage()).isEqualTo("issue on A");
assertThat(issue.getInputComponent()).isEqualTo(inputFile);
assertThat(issue.getLine()).isEqualTo(2);
if (withFlowsAndCost) {
assertThat(issue.getCost()).isEqualTo(42);
assertThat(issue.flows).hasSize(1).allMatch(secondary -> secondary.size() == 2);
AnalyzerMessage secondary = issue.flows.get(0).get(0);
assertThat(secondary.getMessage()).isEqualTo("secondary message on }");
} else {
assertThat(issue.getCost()).isNull();
assertThat(issue.flows).isEmpty();
}
assertPosition(issue.primaryLocation(), 2, 0, 2, 10);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaFileScannerContextForTestsTest method reportIssue_on_tree.
@Test
void reportIssue_on_tree() {
context.reportIssue(CHECK, classA, "issue on A");
Set<AnalyzerMessage> issues = context.getIssues();
assertThat(issues).hasSize(1);
AnalyzerMessage issue = issues.iterator().next();
assertThat(issue.getCheck()).isInstanceOf(DummyRule.class);
assertThat(issue.getMessage()).isEqualTo("issue on A");
assertThat(issue.getInputComponent()).isEqualTo(inputFile);
assertThat(issue.getLine()).isEqualTo(2);
assertThat(issue.getCost()).isNull();
assertThat(issue.flows).isEmpty();
assertPosition(issue.primaryLocation(), 2, 0, 2, 10);
}
use of org.sonar.java.reporting.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaFileScannerContextForTestsTest method reportIssue_between_trees.
@Test
void reportIssue_between_trees() {
context.reportIssue(CHECK, classA, classB, "issue on A and B");
Set<AnalyzerMessage> issues = context.getIssues();
assertThat(issues).hasSize(1);
AnalyzerMessage issue = issues.iterator().next();
assertThat(issue.getCheck()).isInstanceOf(DummyRule.class);
assertThat(issue.getMessage()).isEqualTo("issue on A and B");
assertThat(issue.getInputComponent()).isEqualTo(inputFile);
assertThat(issue.getLine()).isEqualTo(2);
assertThat(issue.getCost()).isNull();
assertThat(issue.flows).isEmpty();
assertPosition(issue.primaryLocation(), 2, 0, 3, 10);
}
Aggregations