]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
Adding SingleExecutionViolationException.
authorErlend Kristiansen <erlenkr@ifi.uio.no>
Sun, 15 Dec 2013 12:46:49 +0000 (13:46 +0100)
committerErlend Kristiansen <erlenkr@ifi.uio.no>
Sun, 15 Dec 2013 12:46:49 +0000 (13:46 +0100)
Adding test for SIngleExecutionExecutorManager.

software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SingleExecutionExecutorManagerTest.java [new file with mode: 0644]
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/Executor.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/ExecutorManager.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionExecutorManager.java
software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionViolationException.java [new file with mode: 0644]

diff --git a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SingleExecutionExecutorManagerTest.java b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SingleExecutionExecutorManagerTest.java
new file mode 100644 (file)
index 0000000..4345290
--- /dev/null
@@ -0,0 +1,57 @@
+package no.uio.ifi.refaktor.tests;
+
+
+import static org.junit.Assert.assertTrue;
+import no.uio.ifi.refaktor.changers.Executor;
+import no.uio.ifi.refaktor.changers.ExecutorManager;
+import no.uio.ifi.refaktor.changers.RefaktorChangerException;
+import no.uio.ifi.refaktor.changers.SingleExecutionExecutorManager;
+import no.uio.ifi.refaktor.changers.SingleExecutionViolationException;
+import no.uio.ifi.refaktor.changers.UndoResources;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.junit.Before;
+import org.junit.Test;
+
+public class SingleExecutionExecutorManagerTest {
+       
+       private class ExecutorMock implements Executor {
+
+               boolean isExecuted = false;
+
+               @Override
+               public void checkPreconditions() throws RefaktorChangerException {
+                       return; 
+               }
+
+               @Override
+               public void executeChange(IProgressMonitor monitor, UndoResources undoResources) throws CoreException {
+                       isExecuted = true;
+               }
+
+       }
+
+       private ExecutorMock executor;
+       private ExecutorManager executorManager;
+
+       @Before
+       public void setUp() throws Exception {
+               executor = new ExecutorMock();
+               executorManager = new SingleExecutionExecutorManager(executor);
+       }
+
+       @Test
+       public void testExecution() throws CoreException {
+               executorManager.executeChange(new NullProgressMonitor(), null);
+               assertTrue(executor.isExecuted);
+       }
+       
+       @Test(expected=SingleExecutionViolationException.class)
+       public void testDoubleExecution() throws CoreException {
+               executorManager.executeChange(new NullProgressMonitor(), null);
+               assertTrue(executor.isExecuted);
+               executorManager.executeChange(new NullProgressMonitor(), null);
+       }
+}
index 79397f80aaeb99282cb36a743b4b83d7aac48a77..7764e4f48bc9093bf2a341bbae27383095676b53 100644 (file)
@@ -3,7 +3,7 @@ package no.uio.ifi.refaktor.changers;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 
-interface Executor {
+public interface Executor {
 
        public void checkPreconditions() throws RefaktorChangerException;
        public void executeChange(IProgressMonitor monitor, UndoResources undoResources) throws CoreException;
index f640a7ee0bc4db3c9a8a7a8f9a215a87284e45b7..bc38721c1edfd98d89573aee567e5c5dae2c5041 100644 (file)
@@ -3,7 +3,7 @@ package no.uio.ifi.refaktor.changers;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 
-interface ExecutorManager {
+public interface ExecutorManager {
 
        public void executeChange(IProgressMonitor monitor, UndoResources undoResources) throws CoreException;
 
index 1b4843cb33860a9ad0e987b6cab8ecea4ce44d42..f7b894b49ae3439bcaec062736d687b354b88298 100644 (file)
@@ -3,7 +3,7 @@ package no.uio.ifi.refaktor.changers;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 
-class SingleExecutionExecutorManager implements ExecutorManager {
+public class SingleExecutionExecutorManager implements ExecutorManager {
        private final Executor executor;
        private boolean isExecuted;
        
@@ -14,7 +14,9 @@ class SingleExecutionExecutorManager implements ExecutorManager {
 
        @Override
        public void executeChange(IProgressMonitor monitor, UndoResources undoResources) throws CoreException {
-               assert !isExecuted: "The change can only be executed once!";
+               if (isExecuted)
+                       throw new SingleExecutionViolationException("The change can only be executed once!");
+
                executor.executeChange(monitor, undoResources);
                markAsExecuted();
        }
diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionViolationException.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionViolationException.java
new file mode 100644 (file)
index 0000000..328ff66
--- /dev/null
@@ -0,0 +1,10 @@
+package no.uio.ifi.refaktor.changers;
+
+public class SingleExecutionViolationException extends RefaktorChangerException {
+
+       private static final long serialVersionUID = 6633508105802831716L;
+
+       public SingleExecutionViolationException(String message) {
+               super(message);
+       }
+}