use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method verify_missing_expected_issue.
@Test
public void verify_missing_expected_issue() {
IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues().withoutIssue(1);
try {
JavaCheckVerifier.verify(FILENAME_ISSUES, visitor);
Fail.fail("");
} catch (AssertionError e) {
assertThat(e).hasMessage("Expected {1=[{MESSAGE=message}]}");
}
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method verify_line_issues_with_java_version.
@Test
public void verify_line_issues_with_java_version() {
IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues();
JavaCheckVerifier.verify(FILENAME_ISSUES, visitor, 7);
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class JavaCheckVerifierTest method verify_combined_missing_expected_and_unexpected_issues.
@Test
public void verify_combined_missing_expected_and_unexpected_issues() {
IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues().withIssue(4, "extra message").withoutIssue(1);
try {
JavaCheckVerifier.verify(FILENAME_ISSUES, visitor);
Fail.fail("");
} catch (AssertionError e) {
assertThat(e).hasMessage("Expected {1=[{MESSAGE=message}]}, Unexpected at [4]");
}
}
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("");
}
}
use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.
the class MethodMatcherTest method test_copy.
@Test
public void test_copy() throws Exception {
MethodMatcher vanilla = MethodMatcher.create().typeDefinition("Test").name("f").withoutParameter();
MethodMatcher copyInt = vanilla.copy().addParameter("int");
MethodMatcher copyString = vanilla.copy().addParameter("java.lang.String");
Map<MethodMatcher, List<Integer>> matches = new HashMap<>();
matches.put(vanilla, new ArrayList<>());
matches.put(copyInt, new ArrayList<>());
matches.put(copyString, new ArrayList<>());
JavaCheckVerifier.verifyNoIssue("src/test/files/matcher/Copy.java", new IssuableSubscriptionVisitor() {
@Override
public List<Tree.Kind> nodesToVisit() {
return Collections.singletonList(Tree.Kind.METHOD);
}
@Override
public void visitNode(Tree tree) {
MethodTree methodTree = (MethodTree) tree;
matches.forEach((matcher, list) -> {
if (matcher.matches(methodTree)) {
list.add(methodTree.firstToken().line());
}
});
}
});
assertThat(matches.get(vanilla)).containsExactly(3);
assertThat(matches.get(copyInt)).containsExactly(5);
assertThat(matches.get(copyString)).containsExactly(7);
}
Aggregations