use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method rule_without_annotation_should_fail_with_a_clear_message.
@Test
public void rule_without_annotation_should_fail_with_a_clear_message() {
class NotAnnotatedCheck extends IssuableSubscriptionVisitor {
@Override
public List<Tree.Kind> nodesToVisit() {
return Collections.singletonList(Tree.Kind.METHOD);
}
@Override
public void visitNode(Tree tree) {
reportIssue(tree, "yolo", Collections.emptyList(), 42);
}
}
NotAnnotatedCheck check = new NotAnnotatedCheck();
Throwable throwable = catchThrowable(() -> JavaCheckVerifier.verify("src/test/files/JavaCheckVerifierNoIssue.java", check));
assertThat(throwable).isInstanceOf(AssertionError.class).hasMessage("Rules should be annotated with '@Rule(key = \"...\")' annotation (org.sonar.check.Rule).");
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method verify_unexpected_issue.
@Test
public void verify_unexpected_issue() {
IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues().withIssue(4, "extra message");
try {
JavaCheckVerifier.verify(FILENAME_ISSUES, visitor);
Fail.fail("");
} catch (AssertionError e) {
assertThat(e).hasMessage("Unexpected at [4]");
}
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method test_with_no_semantic.
@Test
public void test_with_no_semantic() throws Exception {
IssuableSubscriptionVisitor noIssueVisitor = new FakeVisitor();
JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_ISSUES, noIssueVisitor);
JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_NO_ISSUE, noIssueVisitor);
try {
JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_ISSUES, new FakeVisitor().withDefaultIssues());
Fail.fail("");
} catch (AssertionError e) {
assertThat(e.getMessage()).contains("No issues expected but got:");
}
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method verify_with_provided_test_jar.
@Test
public void verify_with_provided_test_jar() throws IOException {
String testJarsPathname = "target/my-test-jars";
File file = new File(testJarsPathname);
if (file.exists()) {
file.delete();
}
if (file.mkdir()) {
IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues();
JavaCheckVerifier.verify(FILENAME_ISSUES, visitor, testJarsPathname);
file.delete();
} else {
Fail.fail("");
}
}
Aggregations