Skip to content

Commit 3a77cff

Browse files
committed
Localise the UndefinedStepTracker in the Runtime
Localise the UndefinedStepTracker in the Runtime and remove that argument from the constructor. Use that the optionalGlue argument is null, as the cue to let the Runtime create the default RuntimeGlue. When the optionalGlue argument is not null, the glue injected with that argument will be used by the Runtime.
1 parent c8feb10 commit 3a77cff

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

core/src/main/java/cucumber/runtime/Runtime.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Runtime implements UnreportedStepExecutor {
4444
private static final byte ERRORS = 0x1;
4545

4646
private final SummaryCounter summaryCounter;
47-
final UndefinedStepsTracker undefinedStepsTracker;
47+
final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
4848

4949
private final Glue glue;
5050
private final RuntimeOptions runtimeOptions;
@@ -60,22 +60,19 @@ public class Runtime implements UnreportedStepExecutor {
6060
private ScenarioImpl scenarioResult = null;
6161

6262
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) {
63-
UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
64-
return new Runtime(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions,
65-
undefinedStepsTracker, new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)));
63+
return new Runtime(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions, null);
6664
}
6765

6866
public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection<? extends Backend> backends,
69-
RuntimeOptions runtimeOptions, UndefinedStepsTracker undefinedStepsTracker, RuntimeGlue glue) {
67+
RuntimeOptions runtimeOptions, RuntimeGlue optionalGlue) {
7068
if (backends.isEmpty()) {
7169
throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH.");
7270
}
7371
this.resourceLoader = resourceLoader;
7472
this.classLoader = classLoader;
7573
this.backends = backends;
7674
this.runtimeOptions = runtimeOptions;
77-
this.undefinedStepsTracker = undefinedStepsTracker;
78-
this.glue = glue;
75+
this.glue = optionalGlue != null ? optionalGlue : new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
7976
this.summaryCounter = new SummaryCounter(runtimeOptions.monochrome);
8077

8178
for (Backend backend : backends) {

core/src/test/java/cucumber/runtime/RuntimeTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import cucumber.runtime.io.ClasspathResourceLoader;
66
import cucumber.runtime.io.ResourceLoader;
77
import cucumber.runtime.model.CucumberFeature;
8-
import cucumber.runtime.xstream.LocalizedXStreams;
98
import gherkin.I18n;
109
import gherkin.formatter.JSONFormatter;
1110
import gherkin.formatter.Reporter;
@@ -369,14 +368,12 @@ private Runtime createRuntime(String... runtimeArgs) {
369368

370369
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
371370
Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
372-
UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
373-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, undefinedStepsTracker,
374-
new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)));
371+
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, null);
375372
}
376373

377374
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
378375
Collection<Backend> backends, RuntimeOptions runtimeOptions, RuntimeGlue glue) {
379-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, new UndefinedStepsTracker(), glue);
376+
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, glue);
380377
}
381378

382379
private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, String... runtimeArgs) {
@@ -403,7 +400,7 @@ private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, boolean i
403400
mockHook(glue, hook, isBefore);
404401
Collection<Backend> backends = Arrays.asList(backend);
405402

406-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, new UndefinedStepsTracker(), glue);
403+
return createRuntime(resourceLoader, classLoader, backends, runtimeOptions, glue);
407404
}
408405

409406
private void mockMatch(RuntimeGlue glue, StepDefinitionMatch match, boolean isAmbiguous) {

java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
import cucumber.runtime.DuplicateStepDefinitionException;
77
import cucumber.runtime.Glue;
88
import cucumber.runtime.Runtime;
9-
import cucumber.runtime.RuntimeGlue;
109
import cucumber.runtime.RuntimeOptions;
11-
import cucumber.runtime.UndefinedStepsTracker;
1210
import cucumber.runtime.io.ClasspathResourceLoader;
1311
import cucumber.runtime.io.ResourceLoader;
14-
import cucumber.runtime.xstream.LocalizedXStreams;
1512
import gherkin.I18n;
1613
import gherkin.formatter.Reporter;
1714
import gherkin.formatter.model.Comment;
@@ -153,8 +150,6 @@ private <T> Set<T> asSet(T... items) {
153150

154151
private Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
155152
Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
156-
UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();
157-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, undefinedStepsTracker,
158-
new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)));
153+
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, null);
159154
}
160155
}

0 commit comments

Comments
 (0)