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
No related branches found
No related tags found
No related merge requests found
......@@ -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.
}
......
......
......@@ -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();
}
......
......
......@@ -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 to comment