Commit 102a0b01 authored by Christian Wulf's avatar Christian Wulf

added InvalidTestCaseSetupException;

changed onStarting() from public to protected
parent 93f23416
......@@ -440,7 +440,7 @@ public abstract class AbstractStage {
* {@link IllegalArgumentException#IllegalArgumentException(String, Throwable)}.
* Always pass the original exception to the new unchecked exception to allow easy debugging.
*/
public void onStarting() {
protected void onStarting() {
logger.trace(ON_STATE_CHANGE_MARKER, "Starting {}", this);
changeState(StageState.STARTED);
calledOnStarting = true;
......
......@@ -110,4 +110,8 @@ public final class StageFacade {
stage.setLevelIndex(levelIndex);
}
public void onStarting(final AbstractStage stage) {
stage.onStarting();
}
}
......@@ -20,12 +20,13 @@ import java.util.Set;
import teetime.framework.AbstractStage;
import teetime.framework.InputPort;
import teetime.framework.StageFacade;
public final class StartingSignal implements ISignal {
@Override
public void trigger(final AbstractStage stage) {
stage.onStarting();
StageFacade.INSTANCE.onStarting(stage);
}
@Override
......
package teetime.framework.test;
/**
* Represents an exception in the setup of a test case.
*
* @author Christian Wulf (chw)
*
*/
public class InvalidTestCaseSetupException extends RuntimeException {
private static final long serialVersionUID = -1380841389726636785L;
public InvalidTestCaseSetupException(final String message) {
super(message);
}
}
......@@ -41,7 +41,7 @@ public final class StageTester {
public static StageTester test(final AbstractStage stage) { // NOPMD
if (stage.getCurrentState() != StageState.CREATED) {
throw new IllegalStateException("This stage has already been tested in this test method. Move this test into a new test method.");
throw new InvalidTestCaseSetupException("This stage has already been tested in this test method. Move this test into a new test method.");
}
return new StageTester(stage);
}
......@@ -89,7 +89,7 @@ public final class StageTester {
/**
* This method will start the test and block until it is finished.
*
*
* @return
*
* @throws ExecutionException
......@@ -113,6 +113,10 @@ public final class StageTester {
private static class TestConfiguration<I> extends Configuration {
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public TestConfiguration(final List<InputHolder<I>> inputHolders, final AbstractStage stage, final List<OutputHolder<?>> outputHolders) {
if (inputHolders.isEmpty() && outputHolders.isEmpty()) {
throw new InvalidTestCaseSetupException("The stage under test must at least receive or send anything.");
}
for (InputHolder<I> inputHolder : inputHolders) {
final InitialElementProducer<I> producer = new InitialElementProducer<I>(inputHolder.getInputElements());
connectPorts(producer.getOutputPort(), inputHolder.getPort());
......
......@@ -20,13 +20,40 @@ public class StageTesterTest {
List<Integer> outputElements = new ArrayList<>();
test(producer)
// .send(4,5,6).to(port)
.receive(outputElements).from(producer.getOutputPort())
.start();
assertThat(outputElements, contains(1, 2, 3));
}
@Test(expected = InvalidTestCaseSetupException.class)
public void testProducerAlreadyStarted() throws Exception {
InitialElementProducer<Integer> producer = new InitialElementProducer<>(1, 2, 3);
// let the producer be used once before testing it actually
test(producer).receive(new ArrayList<Integer>()).from(producer.getOutputPort()).start();
List<Integer> outputElements = new ArrayList<>();
test(producer)
.receive(outputElements).from(producer.getOutputPort())
.start();
assertThat(outputElements, contains(1, 2, 3));
}
@Test(expected = InvalidTestCaseSetupException.class)
public void testProducerWithoutReceive() throws Exception {
InitialElementProducer<Integer> producer = new InitialElementProducer<>(1, 2, 3);
List<Integer> outputElements = new ArrayList<>();
test(producer)
.start();
assertThat(outputElements, contains(1, 2, 3));
}
@Test
public void testConsumer() throws Exception {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment