Search in sources :

Example 1 with RefactoringException

use of spoon.refactoring.RefactoringException in project spoon by INRIA.

the class MethodsRefactoringTest method testCtParameterRemoveRefactoringValidationCheck.

@Test
public void testCtParameterRemoveRefactoringValidationCheck() throws FileNotFoundException {
    String testPackagePath = "spoon/test/refactoring/parameter/testclasses";
    final Launcher launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    SpoonModelBuilder comp = launcher.createCompiler();
    comp.addInputSource(SpoonResourceHelper.createResource(new File("./src/test/java/" + testPackagePath)));
    comp.build();
    Factory factory = comp.getFactory();
    CtType<?> typeR = factory.Class().get(TypeR.class);
    CtMethod<?> methodTypeR_method1 = typeR.getMethodsByName("method1").get(0);
    CtParameterRemoveRefactoring refactor = new CtParameterRemoveRefactoring().setTarget(methodTypeR_method1.getParameters().get(0));
    refactor.setTarget(methodTypeR_method1.getParameters().get(0));
    // check that each to be refactored method has one parameter
    List<CtExecutable<?>> execs = refactor.getTargetExecutables();
    execs.forEach(exec -> {
        // check that each to be modified method has one parameter
        assertEquals(1, exec.getParameters().size());
    });
    // try refactor
    try {
        refactor.refactor();
        fail();
    } catch (RefactoringException e) {
        this.getClass();
    }
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtParameterRemoveRefactoring(spoon.refactoring.CtParameterRemoveRefactoring) Launcher(spoon.Launcher) Factory(spoon.reflect.factory.Factory) RefactoringException(spoon.refactoring.RefactoringException) File(java.io.File) CtExecutable(spoon.reflect.declaration.CtExecutable) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 Launcher (spoon.Launcher)1 SpoonModelBuilder (spoon.SpoonModelBuilder)1 CtParameterRemoveRefactoring (spoon.refactoring.CtParameterRemoveRefactoring)1 RefactoringException (spoon.refactoring.RefactoringException)1 CtExecutable (spoon.reflect.declaration.CtExecutable)1 Factory (spoon.reflect.factory.Factory)1