Search in sources :

Example 11 with IssuableSubscriptionVisitor

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 at [1]");
    }
}
Also used : IssuableSubscriptionVisitor(org.sonar.plugins.java.api.IssuableSubscriptionVisitor) Test(org.junit.Test)

Example 12 with IssuableSubscriptionVisitor

use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.

the class JavaCheckVerifierTest method verify_issue_on_file.

@Test
public void verify_issue_on_file() {
    String expectedMessage = "messageOnFile";
    IssuableSubscriptionVisitor visitor = new FakeVisitor().withIssueOnFile(expectedMessage);
    JavaCheckVerifier.verifyIssueOnFile(FILENAME_ISSUES, expectedMessage, visitor);
}
Also used : IssuableSubscriptionVisitor(org.sonar.plugins.java.api.IssuableSubscriptionVisitor) Test(org.junit.Test)

Example 13 with IssuableSubscriptionVisitor

use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.

the class JavaCheckVerifierTest method verify_should_fail_when_using_incorrect_secondaryLocation.

@Test
public void verify_should_fail_when_using_incorrect_secondaryLocation() throws IOException {
    IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues();
    try {
        JavaCheckVerifier.verify("src/test/files/JavaCheckVerifierIncorrectSecondaryLocation.java", visitor);
        Fail.fail("");
    } catch (AssertionError e) {
        assertThat(e).hasMessage("Secondary locations: expected: [] unexpected:[3]");
    }
}
Also used : IssuableSubscriptionVisitor(org.sonar.plugins.java.api.IssuableSubscriptionVisitor) Test(org.junit.Test)

Example 14 with IssuableSubscriptionVisitor

use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.

the class JavaCheckVerifierTest method test_with_no_semantic_and_java_version.

@Test
public void test_with_no_semantic_and_java_version() throws Exception {
    int java_8 = 8;
    IssuableSubscriptionVisitor noIssueVisitor = new FakeVisitor();
    JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_ISSUES, noIssueVisitor, java_8);
    JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_NO_ISSUE, noIssueVisitor, java_8);
    try {
        JavaCheckVerifier.verifyNoIssueWithoutSemantic(FILENAME_ISSUES, new FakeVisitor().withDefaultIssues(), java_8);
        Fail.fail("");
    } catch (AssertionError e) {
        assertThat(e.getMessage()).contains("No issues expected but got:");
    }
}
Also used : IssuableSubscriptionVisitor(org.sonar.plugins.java.api.IssuableSubscriptionVisitor) Test(org.junit.Test)

Example 15 with IssuableSubscriptionVisitor

use of org.sonar.plugins.java.api.IssuableSubscriptionVisitor in project sonar-java by SonarSource.

the class JavaCheckVerifierTest method verify_line_issues.

@Test
public void verify_line_issues() {
    IssuableSubscriptionVisitor visitor = new FakeVisitor().withDefaultIssues();
    JavaCheckVerifier.verify(FILENAME_ISSUES, visitor);
}
Also used : IssuableSubscriptionVisitor(org.sonar.plugins.java.api.IssuableSubscriptionVisitor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 IssuableSubscriptionVisitor (org.sonar.plugins.java.api.IssuableSubscriptionVisitor)24 File (java.io.File)5 Tree (org.sonar.plugins.java.api.tree.Tree)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 JavaAstScanner (org.sonar.java.ast.JavaAstScanner)1 SubscriptionVisitor (org.sonar.java.ast.visitors.SubscriptionVisitor)1 JavaTree (org.sonar.java.model.JavaTree)1