Search in sources :

Example 1 with VisitorsBridge

use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.

the class JavaTypeTest method test_fully_qualified_name.

@Test
public void test_fully_qualified_name() {
    File bytecodeDir = new File("target/test-classes");
    ClassFullQualifiedNameVerifierVisitor visitor = new ClassFullQualifiedNameVerifierVisitor(bytecodeDir);
    JavaAstScanner.scanSingleFileForTests(new File("src/test/java/org/sonar/java/resolve/targets/FullyQualifiedName.java"), new VisitorsBridge(Collections.singletonList(visitor), Lists.newArrayList(bytecodeDir), null));
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) Test(org.junit.Test)

Example 2 with VisitorsBridge

use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.

the class PackageInfoCheckTest method testNoPackageInfo.

@Test
public void testNoPackageInfo() throws Exception {
    PackageInfoCheck check = new PackageInfoCheck();
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/packageInfo/nopackageinfo/nopackageinfo.java"), new VisitorsBridge(check));
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/packageInfo/nopackageinfo/HelloWorld.java"), new VisitorsBridge(check));
    Set<File> set = check.directoriesWithoutPackageFile;
    assertThat(set).hasSize(1);
    assertThat(set.iterator().next().getName()).isEqualTo("nopackageinfo");
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) Test(org.junit.Test)

Example 3 with VisitorsBridge

use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.

the class PackageInfoCheckTest method test.

@Test
public void test() throws Exception {
    PackageInfoCheck check = new PackageInfoCheck();
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/packageInfo/HelloWorld.java"), new VisitorsBridge(check));
    assertThat(check.directoriesWithoutPackageFile).isEmpty();
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) Test(org.junit.Test)

Example 4 with VisitorsBridge

use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.

the class AbstractMethodDetectionTest method withoutParameter.

@Test
public void withoutParameter() throws Exception {
    Visitor visitor = new Visitor(ImmutableList.of(MethodMatcher.create().typeDefinition("A").name("method").withoutParameter()));
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/AbstractMethodDetection.java"), new VisitorsBridge(visitor));
    assertThat(visitor.lines).containsExactly(14);
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) Test(org.junit.Test)

Example 5 with VisitorsBridge

use of org.sonar.java.model.VisitorsBridge in project sonar-java by SonarSource.

the class AbstractMethodDetectionTest method detected.

@Test
public void detected() {
    Visitor visitor = new Visitor(ImmutableList.of(MethodMatcher.create().typeDefinition("A").name("method").addParameter("int"), MethodMatcher.create().typeDefinition("A").name("method").addParameter("java.lang.String[]")));
    JavaAstScanner.scanSingleFileForTests(new File("src/test/files/checks/AbstractMethodDetection.java"), new VisitorsBridge(visitor));
    assertThat(visitor.lines).hasSize(2);
    assertThat(visitor.lines).containsExactly(15, 17);
}
Also used : VisitorsBridge(org.sonar.java.model.VisitorsBridge) File(java.io.File) Test(org.junit.Test)

Aggregations

VisitorsBridge (org.sonar.java.model.VisitorsBridge)26 File (java.io.File)25 Test (org.junit.Test)24 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)11 RecognitionException (com.sonar.sslr.api.RecognitionException)4 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 SonarComponents (org.sonar.java.SonarComponents)4 ArrayList (java.util.ArrayList)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 Measurer (org.sonar.java.Measurer)2 SubscriptionVisitor (org.sonar.java.ast.visitors.SubscriptionVisitor)2 MethodTree (org.sonar.plugins.java.api.tree.MethodTree)2 InterruptedIOException (java.io.InterruptedIOException)1 HashMap (java.util.HashMap)1 BeforeClass (org.junit.BeforeClass)1 SensorContext (org.sonar.api.batch.SensorContext)1 InputPath (org.sonar.api.batch.fs.InputPath)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1