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();
}
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();
}
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");
}
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\");"));
}
Aggregations