From: Erlend Kristiansen Date: Sun, 15 Dec 2013 12:46:49 +0000 (+0100) Subject: Adding SingleExecutionViolationException. X-Git-Url: http://git.uio.no/git/?a=commitdiff_plain;h=f2c117f3f53ccd01755c1c0d69bc3b1886e7bf70;p=ifi-stolz-refaktor.git Adding SingleExecutionViolationException. Adding test for SIngleExecutionExecutorManager. --- 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 index 00000000..43452901 --- /dev/null +++ b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SingleExecutionExecutorManagerTest.java @@ -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); + } +} diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/Executor.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/Executor.java index 79397f80..7764e4f4 100644 --- a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/Executor.java +++ b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/Executor.java @@ -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; diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/ExecutorManager.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/ExecutorManager.java index f640a7ee..bc38721c 100644 --- a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/ExecutorManager.java +++ b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/ExecutorManager.java @@ -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; diff --git a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionExecutorManager.java b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionExecutorManager.java index 1b4843cb..f7b894b4 100644 --- a/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionExecutorManager.java +++ b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionExecutorManager.java @@ -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 index 00000000..328ff663 --- /dev/null +++ b/software/no.uio.ifi.refaktor/src/no/uio/ifi/refaktor/changers/SingleExecutionViolationException.java @@ -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); + } +}