1 package no.uio.ifi.refaktor.tests;
3 import static no.uio.ifi.refaktor.tests.assertion.RefaktorAssert.assertThat;
4 import static org.junit.Assert.fail;
6 import java.util.Arrays;
7 import java.util.Collection;
9 import no.uio.ifi.refaktor.analyze.candidates.ExtractLocalVariableCandidate;
10 import no.uio.ifi.refaktor.analyze.exceptions.RefaktorAnalyzerException;
11 import no.uio.ifi.refaktor.change.changers.ProjectWideRefactorChanger;
12 import no.uio.ifi.refaktor.examples.manager.ExampleCodeManager;
13 import no.uio.ifi.refaktor.factories.ExtractLocalVariableFactory;
14 import no.uio.ifi.refaktor.forTests.Refactorer;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.junit.runners.Parameterized;
21 import org.junit.runners.Parameterized.Parameter;
22 import org.junit.runners.Parameterized.Parameters;
24 @RunWith(Parameterized.class)
25 public class ProjectWideExtractLocalVariableChangerTest {
28 Refactorer setup() throws CoreException;
33 public static Collection<Object[]> data() throws CoreException {
34 Object debug = ExampleCodeManager.INSTANCE.getProject();
35 return Arrays.asList(new Object[][] {
36 /* [stolz] Defer execution until Example-project extracted */
37 // { new Setup() { public RefaktorChanger setup() throws CoreException {
38 // return new ProjectWideExtractAndMoveMethodChanger(ExampleCodeManager.INSTANCE.getProject());}
40 /* Test with the next line to check that repeated execution indeed always works on a fresh workspace: */
41 /* Anna's refactoring with the same API goes here: */
42 { new Setup() { public Refactorer setup() throws CoreException {return new ProjectWideRefactorChanger(ExampleCodeManager.INSTANCE.getProject(), new ExtractLocalVariableFactory<ExtractLocalVariableCandidate>());}} }
51 // public void testAnalyzeAndChange() throws CoreException {
52 // ExampleCodeManager.INSTANCE.loadExampleCode(); // could be in setup() as well.
53 // RefaktorChanger changer = setup.setup();
55 // changer.checkPreconditions();
56 // changer.execute(new NullProgressMonitor());
57 // } catch (RefaktorAnalyzerException e) {
58 // fail("Preconditions failed to validate.");
59 // } catch (CoreException e) {
60 // fail("Execution failed.");
63 // ExampleCodeManager.INSTANCE.cleanBuild();
64 // assertThat("Project has errors after change.", !ExampleCodeManager.INSTANCE.projectHasErrors());
68 public void testAnalyzeAndChange() throws CoreException{
69 ExampleCodeManager.INSTANCE.loadExampleCode(); // could be in setup() as well.
70 Refactorer refactorer = setup.setup();
72 refactorer.refactor(new NullProgressMonitor());
73 } catch (RefaktorAnalyzerException e) {
74 fail("Preconditions failed to validate.");
75 } catch (CoreException e) {
76 fail("Execution failed.");
79 ExampleCodeManager.INSTANCE.cleanBuild();
80 assertThat("Project has errors after change.", !ExampleCodeManager.INSTANCE.projectHasErrors());