Skip to content
Snippets Groups Projects
Commit 4eccf28c authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

fixes #195 Config instances can only be used once

parent b1b5baf1
Branches
Tags
No related merge requests found
...@@ -25,6 +25,16 @@ package teetime.framework; ...@@ -25,6 +25,16 @@ package teetime.framework;
*/ */
public class Configuration extends AbstractCompositeStage { public class Configuration extends AbstractCompositeStage {
private boolean executed;
boolean isExecuted() {
return executed;
}
void setExecuted(final boolean executed) {
this.executed = executed;
}
protected Configuration() { protected Configuration() {
// protected ctor to prevent direct instantiation. // protected ctor to prevent direct instantiation.
} }
......
...@@ -113,6 +113,10 @@ public final class Execution<T extends Configuration> implements UncaughtExcepti ...@@ -113,6 +113,10 @@ public final class Execution<T extends Configuration> implements UncaughtExcepti
public Execution(final T configuration, final boolean validationEnabled, final IExceptionListenerFactory factory) { public Execution(final T configuration, final boolean validationEnabled, final IExceptionListenerFactory factory) {
this.configuration = configuration; this.configuration = configuration;
this.factory = factory; this.factory = factory;
if (configuration.isExecuted()) {
throw new IllegalStateException("Configuration was already executed");
}
configuration.setExecuted(true);
if (validationEnabled) { if (validationEnabled) {
validateStages(); validateStages();
} }
......
...@@ -198,4 +198,11 @@ public class ExecutionTest { ...@@ -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
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment