]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
Adding test and implementation for ProjectWideSearchBasedExtractAndMoveMethodChanger.
authorErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 29 Jan 2014 13:53:03 +0000 (14:53 +0100)
committerErlend Kristiansen <erlenkr@ifi.uio.no>
Wed, 29 Jan 2014 13:53:28 +0000 (14:53 +0100)
software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChanger.java [new file with mode: 0644]
software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChangerTest.java [new file with mode: 0644]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/analyze/ProjectWideSearchBasedExtractAndMoveMethodAnalyzer.java

diff --git a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChanger.java b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChanger.java
new file mode 100644 (file)
index 0000000..a21e19e
--- /dev/null
@@ -0,0 +1,30 @@
+package no.uio.ifi.refaktor.tests;
+
+import no.uio.ifi.refaktor.analyze.ProjectWideSearchBasedExtractAndMoveMethodAnalyzer;
+import no.uio.ifi.refaktor.changers.RefaktorChanger;
+import no.uio.ifi.refaktor.changers.RefaktorChangerException;
+import no.uio.ifi.refaktor.changers.SearchBasedAnalyzerChanger;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class ProjectWideSearchBasedExtractAndMoveMethodChanger implements RefaktorChanger {
+
+       private SearchBasedAnalyzerChanger changer;
+
+       public ProjectWideSearchBasedExtractAndMoveMethodChanger(IProject project) {
+               changer = new SearchBasedAnalyzerChanger(new ProjectWideSearchBasedExtractAndMoveMethodAnalyzer(project));
+       }
+
+       @Override
+       public void checkPreconditions() throws RefaktorChangerException {
+               changer.checkPreconditions();
+       }
+
+       @Override
+       public void executeChange(IProgressMonitor monitor) throws CoreException {
+               changer.executeChange(monitor);
+       }
+
+}
diff --git a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChangerTest.java b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/ProjectWideSearchBasedExtractAndMoveMethodChangerTest.java
new file mode 100644 (file)
index 0000000..00bfc7d
--- /dev/null
@@ -0,0 +1,36 @@
+package no.uio.ifi.refaktor.tests;
+
+import static no.uio.ifi.refaktor.RefaktorAssert.assertThat;
+import static org.junit.Assert.fail;
+import no.uio.ifi.refaktor.changers.RefaktorChanger;
+import no.uio.ifi.refaktor.changers.RefaktorChangerException;
+import no.uio.ifi.refaktor.examples.manager.ExampleCodeManager;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ProjectWideSearchBasedExtractAndMoveMethodChangerTest {
+
+       @Before
+       public void setUp() throws Exception {
+               ExampleCodeManager.INSTANCE.loadExampleCode();
+       }
+
+       @Test
+       public void testAnalyzeAndChange() {
+               RefaktorChanger changer = new ProjectWideSearchBasedExtractAndMoveMethodChanger(ExampleCodeManager.INSTANCE.getProject());
+               try {
+                       changer.checkPreconditions();
+                       changer.executeChange(new NullProgressMonitor());
+               } catch (RefaktorChangerException e) {
+                       fail("Preconditions failed to validate.A");
+               } catch (CoreException e) {
+                       fail("Execution failed.");
+               }
+               
+               ExampleCodeManager.INSTANCE.cleanBuild();
+               assertThat("Project has errors after change.", !ExampleCodeManager.INSTANCE.projectHasErrors());
+       }
+}
index e1eb56fd54ac7298495c7d5afe815b9dfa8d5169..4bfd0be71c1971715a3a744fcd3ce9fbe7bb334d 100644 (file)
@@ -14,6 +14,10 @@ public class ProjectWideSearchBasedExtractAndMoveMethodAnalyzer extends PackageF
 
        private final IProject project;
 
+       public ProjectWideSearchBasedExtractAndMoveMethodAnalyzer(IProject project) {
+               this(project, new AnalysisStatistics());
+       }
+
        public ProjectWideSearchBasedExtractAndMoveMethodAnalyzer(IProject project, AnalysisStatistics statistics) {
                super(statistics);
                this.project = project;