Search in sources :

Example 1 with CompilationTestHelper

use of com.google.errorprone.CompilationTestHelper in project error-prone by google.

the class CompilerBasedAbstractTest method assertCompiles.

private void assertCompiles(ScannerSupplier scannerSupplier) {
    CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(scannerSupplier, getClass()).expectResult(Result.OK);
    for (FileToCompile fileToCompile : filesToCompile) {
        compilationHelper.addSourceLines(fileToCompile.name, fileToCompile.lines);
    }
    compilationHelper.doTest();
}
Also used : CompilationTestHelper(com.google.errorprone.CompilationTestHelper)

Example 2 with CompilationTestHelper

use of com.google.errorprone.CompilationTestHelper in project error-prone by google.

the class CollectionIncompatibleTypeTest method testCastFixes.

@Test
public void testCastFixes() {
    CompilationTestHelper compilationHelperWithCastFix = CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(new ErrorProneScanner(new CollectionIncompatibleType(FixType.CAST))), getClass());
    compilationHelperWithCastFix.addSourceLines("Test.java", "import java.util.Collection;", "public class Test {", "  public void doIt(Collection<String> c1, Collection<Integer> c2) {", "    // BUG: Diagnostic contains: c1.contains((Object) 1);", "    c1.contains(1);", "    // BUG: Diagnostic contains: c1.containsAll((Collection<?>) c2);", "    c1.containsAll(c2);", "  }", "}").doTest();
}
Also used : CompilationTestHelper(com.google.errorprone.CompilationTestHelper) ErrorProneScanner(com.google.errorprone.scanner.ErrorProneScanner) Test(org.junit.Test)

Example 3 with CompilationTestHelper

use of com.google.errorprone.CompilationTestHelper in project error-prone by google.

the class MissingFailTest method testFailImport.

@Test
public void testFailImport() throws Exception {
    TestScanner scanner = new TestScanner();
    CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(scanner), getClass());
    compilationHelper.addSourceLines("test/A.java", "package test;", "import junit.framework.TestCase;", "public class A extends TestCase {", "  public void testMethod() {", "    try {", "      new String();", "    } catch (IllegalArgumentException expected) {}", "  }", "}").doTest();
    assertThat(getOnlyFix(scanner).getImportsToAdd()).containsExactly("import static org.junit.Assert.fail");
    assertThat(getOnlyFix(scanner).getImportsToRemove()).containsExactly("import static junit.framework.TestCase.fail", "import static junit.framework.Assert.fail");
}
Also used : CompilationTestHelper(com.google.errorprone.CompilationTestHelper) Test(org.junit.Test)

Example 4 with CompilationTestHelper

use of com.google.errorprone.CompilationTestHelper in project error-prone by google.

the class MissingFailTest method testFailMessageMultiCatch.

@Test
public void testFailMessageMultiCatch() throws Exception {
    TestScanner scanner = new TestScanner();
    CompilationTestHelper compilationHelper = CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(scanner), getClass());
    compilationHelper.addSourceLines("test/A.java", "package test;", "import junit.framework.TestCase;", "public class A extends TestCase {", "  public void testMethod() {", "    try {", "      new String();", "    } catch (IllegalArgumentException | IllegalStateException expected) {}", "  }", "}").doTest();
    assertThat(getOnlyFix(scanner).getReplacements(new NoopEndPosTable())).containsExactly(Replacement.create(0, 0, "\nfail(\"Expected Exception\");"));
}
Also used : CompilationTestHelper(com.google.errorprone.CompilationTestHelper) Test(org.junit.Test)

Aggregations

CompilationTestHelper (com.google.errorprone.CompilationTestHelper)4 Test (org.junit.Test)3 ErrorProneScanner (com.google.errorprone.scanner.ErrorProneScanner)1