--- /dev/null
+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);
+ }
+}
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;
@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();
}