diff --git a/src/main/java/teetime/framework/Configuration.java b/src/main/java/teetime/framework/Configuration.java index 6ebe6684d00a1db4c88924806f99cf0f5839cfc9..4a225fb22097c002aed3015b28c64f5cc950c0d4 100644 --- a/src/main/java/teetime/framework/Configuration.java +++ b/src/main/java/teetime/framework/Configuration.java @@ -25,6 +25,16 @@ package teetime.framework; */ public class Configuration extends AbstractCompositeStage { + private boolean executed; + + boolean isExecuted() { + return executed; + } + + void setExecuted(final boolean executed) { + this.executed = executed; + } + protected Configuration() { // protected ctor to prevent direct instantiation. } diff --git a/src/main/java/teetime/framework/Execution.java b/src/main/java/teetime/framework/Execution.java index 50279b7c3d07d2fd86af809705f6769c2c60924b..d6971d227f1effa2c9aab9abe84e336be447f289 100644 --- a/src/main/java/teetime/framework/Execution.java +++ b/src/main/java/teetime/framework/Execution.java @@ -113,6 +113,10 @@ public final class Execution<T extends Configuration> implements UncaughtExcepti public Execution(final T configuration, final boolean validationEnabled, final IExceptionListenerFactory factory) { this.configuration = configuration; this.factory = factory; + if (configuration.isExecuted()) { + throw new IllegalStateException("Configuration was already executed"); + } + configuration.setExecuted(true); if (validationEnabled) { validateStages(); } @@ -346,7 +350,7 @@ public final class Execution<T extends Configuration> implements UncaughtExcepti * * @return * a given ExceptionListenerFactory instance - * + * * @since 2.0 */ public IExceptionListenerFactory getFactory() { diff --git a/src/test/java/teetime/framework/ExecutionTest.java b/src/test/java/teetime/framework/ExecutionTest.java index 0e19ac37b98fe418839464d04fa3b5a050649fa1..c256f27b29d92b49ad2087a6a64b76ee88847284 100644 --- a/src/test/java/teetime/framework/ExecutionTest.java +++ b/src/test/java/teetime/framework/ExecutionTest.java @@ -198,4 +198,11 @@ public class ExecutionTest { } + @Test(expected = IllegalStateException.class) + public void executeConfigOnlyOnce() { + NameConfig configuration = new NameConfig(); + new Execution<NameConfig>(configuration); + new Execution<NameConfig>(configuration); // do not execute, but just initialize the execution + } + }