use of org.autorefactor.refactoring.ApplyRefactoringsJob in project AutoRefactor by JnRouvignac.
the class RefactoringRulesTest method testRefactoring0.
private void testRefactoring0() throws Exception {
final String sampleName = testName + "Sample.java";
final File sampleIn = new File(SAMPLES_BASE_DIR, "samples_in/" + sampleName);
assertTrue(testName + ": sample in file " + sampleIn + " should exist", sampleIn.exists());
final File sampleOut = new File(SAMPLES_BASE_DIR, "samples_out/" + sampleName);
assertTrue(testName + ": sample out file " + sampleOut + " should exist", sampleOut.exists());
final String refactoringClassname = testName + "Refactoring";
final RefactoringRule refactoring = getRefactoringClass(refactoringClassname);
assertNotNull(testName + ": refactoring class " + refactoringClassname + " should exist.\n" + "Make sure you added it to the method getAllRefactoringRules() " + "of the " + AllRefactoringRules.class + ".", refactoring);
final String sampleInSource = readAll(sampleIn);
final String sampleOutSource = readAll(sampleOut);
final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment(PACKAGE_NAME);
final ICompilationUnit cu = packageFragment.createCompilationUnit(sampleName, sampleInSource, true, null);
cu.getBuffer().setContents(sampleInSource);
cu.save(null, true);
final IDocument doc = new Document(sampleInSource);
new ApplyRefactoringsJob(null, null, TEST_ENVIRONMENT).applyRefactoring(doc, cu, new AggregateASTVisitor(Arrays.asList(refactoring)), newJavaProjectOptions(Release.javaSE("1.7.0"), 4), new NullProgressMonitor());
final String actual = normalizeJavaSourceCode(doc.get().replaceAll("samples_in", "samples_out"));
final String expected = normalizeJavaSourceCode(sampleOutSource);
assertEquals(testName + ": wrong output;", expected, actual);
}
use of org.autorefactor.refactoring.ApplyRefactoringsJob in project AutoRefactor by JnRouvignac.
the class AllRefactoringRulesTest method testRefactoring0.
private void testRefactoring0() throws Exception {
final File samplesDir = new File(SAMPLES_ALL_BASE_DIR);
final File sampleIn = new File(samplesDir, "samples_in/" + sampleName);
assertTrue(sampleName + ": sample in file " + sampleIn + " should exist", sampleIn.exists());
final File sampleOut = new File(samplesDir, "samples_out/" + sampleName);
assertTrue(sampleName + ": sample out file " + sampleOut + " should exist", sampleOut.exists());
final String sampleInSource = readAll(sampleIn);
final String sampleOutSource = readAll(sampleOut);
final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment(PACKAGE_NAME);
final ICompilationUnit cu = packageFragment.createCompilationUnit(sampleName, sampleInSource, true, null);
cu.getBuffer().setContents(sampleInSource);
cu.save(null, true);
final IDocument doc = new Document(sampleInSource);
new ApplyRefactoringsJob(null, null, TEST_ENVIRONMENT).applyRefactoring(doc, cu, new AggregateASTVisitor(AllRefactoringRules.getAllRefactoringRules()), newJavaProjectOptions(Release.javaSE("1.7.0"), 4), new NullProgressMonitor());
final String actual = normalizeJavaSourceCode(doc.get().replaceAll("samples_in", "samples_out"));
final String expected = normalizeJavaSourceCode(sampleOutSource);
assertEquals(sampleName + ": wrong output;", expected, actual);
}
Aggregations