use of org.sonar.java.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method rule_metadata_undefined_remediation_function.
@Test
public void rule_metadata_undefined_remediation_function() {
@Rule(key = "UndefinedRemediationFunc")
class WrongJson extends FakeVisitor {
}
WrongJson check = new WrongJson();
check.withPreciseIssue(new AnalyzerMessage(check, new File("a"), 1, "message", 0));
JavaCheckVerifier.verify("src/test/files/JavaCheckVerifierNoCost.java", check);
}
use of org.sonar.java.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method rule_metadata_remediation_function.
@Test
public void rule_metadata_remediation_function() {
@Rule(key = "DoesntExists")
class WrongJson extends FakeVisitor {
}
WrongJson check = new WrongJson();
check.withPreciseIssue(new AnalyzerMessage(check, new File("a"), 1, "message", 0));
JavaCheckVerifier.verify("src/test/files/JavaCheckVerifierNoCost.java", check);
}
use of org.sonar.java.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaCheckVerifier method assertMultipleIssue.
private void assertMultipleIssue(Set<AnalyzerMessage> issues) throws AssertionError {
if (issues.isEmpty()) {
Fail.fail("At least one issue expected");
}
List<Integer> unexpectedLines = Lists.newLinkedList();
Multimap<Integer, Expectations.Issue> expected = expectations.issues;
for (AnalyzerMessage issue : issues) {
validateIssue(expected, unexpectedLines, issue);
}
if (!expected.isEmpty() || !unexpectedLines.isEmpty()) {
Collections.sort(unexpectedLines);
List<Integer> expectedLines = expected.keys().stream().sorted().collect(Collectors.toList());
String expectedMsg = !expectedLines.isEmpty() ? ("Expected at " + expectedLines) : "";
String unexpectedMsg = !unexpectedLines.isEmpty() ? ((expectedMsg.isEmpty() ? "" : ", ") + "Unexpected at " + unexpectedLines) : "";
fail(expectedMsg + unexpectedMsg);
}
assertSuperfluousFlows();
}
use of org.sonar.java.AnalyzerMessage in project sonar-java by SonarSource.
the class JavaCheckVerifier method assertSingleIssue.
private static void assertSingleIssue(Integer expectFileIssueOnline, String expectFileIssue, Set<AnalyzerMessage> issues) {
Preconditions.checkState(issues.size() == 1, "A single issue is expected with line " + expectFileIssueOnline);
AnalyzerMessage issue = Iterables.getFirst(issues, null);
assertThat(issue.getLine()).isEqualTo(expectFileIssueOnline);
assertThat(issue.getMessage()).isEqualTo(expectFileIssue);
}
use of org.sonar.java.AnalyzerMessage in project sonar-java by SonarSource.
the class PomCheckContextImpl method getSecondaryAnalyzerMessage.
@VisibleForTesting
AnalyzerMessage getSecondaryAnalyzerMessage(JavaCheck check, File file, Location location) {
TextSpan ts;
if (location.onLine()) {
ts = textSpanForLine(file, location.line);
} else {
XmlLocation startLocation = location.tree.startLocation();
XmlLocation endLocation = location.tree.endLocation();
ts = new TextSpan(startLocation.line(), offsetFromColumn(startLocation.column()), endLocation.line(), offsetFromColumn(endLocation.column()));
if (ts.isEmpty()) {
ts = textSpanForLine(file, startLocation.line());
}
}
return new AnalyzerMessage(check, file, ts, location.msg, 0);
}
Aggregations