]> git.uio.no Git - ifi-stolz-refaktor.git/blob - software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideExtractLocalVariableChangerTest.java
made generic, idk if works, gotta run
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor.tests / src / no / uio / ifi / refaktor / tests / ProjectWideExtractLocalVariableChangerTest.java
1 package no.uio.ifi.refaktor.tests;
2
3 import static no.uio.ifi.refaktor.tests.assertion.RefaktorAssert.assertThat;
4 import static org.junit.Assert.fail;
5
6 import java.util.Arrays;
7 import java.util.Collection;
8
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;
15
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;
23
24 @RunWith(Parameterized.class)
25 public class ProjectWideExtractLocalVariableChangerTest {
26
27         interface Setup {
28                 Refactorer setup() throws CoreException;
29         }
30
31         
32     @Parameters
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());}
39 //                 } }
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>());}} }
43                  
44            });
45     }
46
47     @Parameter
48     public Setup setup;
49
50 //      @Test
51 //      public void testAnalyzeAndChange() throws CoreException {
52 //              ExampleCodeManager.INSTANCE.loadExampleCode(); // could be in setup() as well. 
53 //              RefaktorChanger changer = setup.setup();
54 //              try {
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.");
61 //              }
62 //              
63 //              ExampleCodeManager.INSTANCE.cleanBuild();
64 //              assertThat("Project has errors after change.", !ExampleCodeManager.INSTANCE.projectHasErrors());
65 //      }
66         
67         @Test
68         public void testAnalyzeAndChange() throws CoreException{
69                 ExampleCodeManager.INSTANCE.loadExampleCode(); // could be in setup() as well. 
70                 Refactorer refactorer = setup.setup();
71                 try {
72                         refactorer.refactor(new NullProgressMonitor());
73                 } catch (RefaktorAnalyzerException e) {
74                         fail("Preconditions failed to validate.");
75                 } catch (CoreException e) {
76                         fail("Execution failed.");
77                 }
78                 
79                 ExampleCodeManager.INSTANCE.cleanBuild();
80                 assertThat("Project has errors after change.", !ExampleCodeManager.INSTANCE.projectHasErrors());                
81         }
82 }