Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Decouple UndefinedStepsTracker from Glue #1172

Merged
merged 2 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [2.0.0-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.5...master) (In Git)

* [Core] Use UndefinedStepsTracker from provided RuntimeGlue ([#1019](https://github.com/cucumber/cucumber-jvm/pull/1019) Illapikov)
* [Core] Decouple UndefinedStepsTracker from Glue ([#1019](https://github.com/cucumber/cucumber-jvm/pull/1019) [#1172](https://github.com/cucumber/cucumber-jvm/pull/1172) Illapikov, M.P. Korstanje)
* [Core] Add TestRunStarted event, let Stats handle the exit code ([#1162](https://github.com/cucumber/cucumber-jvm/pull/1162) Björn Rasmusson)
* [Core, JUnit, Android] Add the ambiguous result type ([#1168](https://github.com/cucumber/cucumber-jvm/pull/1168) Björn Rasmusson)
* [Core] Add the SnippetsSuggestedEvent ([#1163](https://github.com/cucumber/cucumber-jvm/pull/1163) Björn Rasmusson)
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/java/cucumber/runtime/Glue.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ public interface Glue {
void reportStepDefinitions(StepDefinitionReporter stepDefinitionReporter);

void removeScenarioScopedGlue();

UndefinedStepsTracker getTracker();
}
10 changes: 2 additions & 8 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class Runtime {

final Stats stats; // package private to be avaiable for tests.
private final UndefinedStepsTracker undefinedStepsTracker;
private final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker();

private final RuntimeOptions runtimeOptions;

Expand Down Expand Up @@ -59,13 +59,7 @@ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collectio
this.classLoader = classLoader;
this.runtimeOptions = runtimeOptions;
final Glue glue;
if (optionalGlue == null) {
this.undefinedStepsTracker = new UndefinedStepsTracker();
glue = new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
} else {
this.undefinedStepsTracker = optionalGlue.getTracker();
glue = optionalGlue;
}
glue = optionalGlue == null ? new RuntimeGlue(new LocalizedXStreams(classLoader)) : optionalGlue;
this.stats = new Stats(runtimeOptions.isMonochrome());
this.bus = new EventBus(stopWatch);
this.runner = new Runner(glue, bus, backends, runtimeOptions);
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/cucumber/runtime/RuntimeGlue.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ public class RuntimeGlue implements Glue {
final List<HookDefinition> beforeHooks = new ArrayList<HookDefinition>();
final List<HookDefinition> afterHooks = new ArrayList<HookDefinition>();

private final UndefinedStepsTracker tracker;
private final LocalizedXStreams localizedXStreams;

public RuntimeGlue(LocalizedXStreams localizedXStreams) {
this(null, localizedXStreams);
}

@Deprecated
public RuntimeGlue(UndefinedStepsTracker tracker, LocalizedXStreams localizedXStreams) {
this.tracker = tracker;
this.localizedXStreams = localizedXStreams;
}

Expand Down Expand Up @@ -113,7 +116,4 @@ private void removeScenarioScopedStepdefs() {
}
}

public UndefinedStepsTracker getTracker() {
return tracker;
}
}
20 changes: 8 additions & 12 deletions core/src/main/java/cucumber/runtime/UndefinedStepsTracker.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package cucumber.runtime;

import cucumber.api.Result;
import cucumber.api.TestCase;
import cucumber.api.TestStep;
import cucumber.api.event.EventHandler;
import cucumber.api.event.EventListener;
import cucumber.api.event.EventPublisher;
Expand Down Expand Up @@ -32,7 +29,6 @@ public class UndefinedStepsTracker implements EventListener {
private final Map<String, String> pathToSourceMap = new HashMap<String, String>();
private final Map<String, FeatureStepMap> pathToStepMap = new HashMap<String, FeatureStepMap>();
private boolean hasUndefinedSteps = false;
private String currentUri;

private EventHandler<TestSourceRead> testSourceReadHandler = new EventHandler<TestSourceRead>() {
@Override
Expand Down Expand Up @@ -160,21 +156,21 @@ private String convertToCodeKeyword(String keyword) {
return keyword.replaceAll("[\\s',!]", "");
}

private class FeatureStepMap {
public final GherkinDialect dialect;
public final Map<Integer, StepNode> stepMap;
private static final class FeatureStepMap {
final GherkinDialect dialect;
final Map<Integer, StepNode> stepMap;

public FeatureStepMap(GherkinDialect dialect, Map<Integer, StepNode> stepMap) {
FeatureStepMap(GherkinDialect dialect, Map<Integer, StepNode> stepMap) {
this.dialect = dialect;
this.stepMap = stepMap;
}
}

private class StepNode {
public final Step step;
public final StepNode previous;
private static final class StepNode {
final Step step;
final StepNode previous;

public StepNode(Step step, StepNode previous) {
StepNode(Step step, StepNode previous) {
this.step = step;
this.previous = previous;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/cucumber/runtime/RuntimeGlueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class RuntimeGlueTest {
@Test
public void throws_duplicate_error_on_dupe_stepdefs() {
RuntimeGlue glue = new RuntimeGlue(new UndefinedStepsTracker(), new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));
RuntimeGlue glue = new RuntimeGlue(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));

StepDefinition a = mock(StepDefinition.class);
when(a.getPattern()).thenReturn("hello");
Expand All @@ -35,7 +35,7 @@ public void removes_glue_that_is_scenario_scoped() {
// But it was too much hassle creating a better test without refactoring RuntimeGlue
// and probably some of its immediate collaborators... Aslak.

RuntimeGlue glue = new RuntimeGlue(new UndefinedStepsTracker(), new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));
RuntimeGlue glue = new RuntimeGlue(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()));

StepDefinition sd = mock(StepDefinition.class);
when(sd.isScenarioScoped()).thenReturn(true);
Expand Down
8 changes: 1 addition & 7 deletions core/src/test/java/cucumber/runtime/RuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,14 @@ private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, boolean i
}
RuntimeOptions runtimeOptions = new RuntimeOptions(args);
Backend backend = mock(Backend.class);
RuntimeGlue glue = mockGlue();
RuntimeGlue glue = mock(RuntimeGlue.class);
mockMatch(glue, match, isAmbiguous);
mockHook(glue, hook, isBefore);
Collection<Backend> backends = Arrays.asList(backend);

return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, glue);
}

private RuntimeGlue mockGlue() {
RuntimeGlue glue = mock(RuntimeGlue.class);
when(glue.getTracker()).thenReturn(new UndefinedStepsTracker());
return glue;
}

private void mockMatch(RuntimeGlue glue, StepDefinitionMatch match, boolean isAmbiguous) {
if (isAmbiguous) {
Exception exception = new AmbiguousStepDefinitionsException(mock(PickleStep.class), Arrays.asList(match, match));
Expand Down
1 change: 0 additions & 1 deletion core/src/test/java/cucumber/runtime/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ private static RuntimeGlue createMockedRuntimeGlueThatMatchesTheSteps(final Map<
final List<SimpleEntry<String, Result>> hooks, final List<String> hookLocations,
final List<Answer<Object>> hookActions) throws Throwable {
RuntimeGlue glue = mock(RuntimeGlue.class);
when(glue.getTracker()).thenReturn(new UndefinedStepsTracker());
TestHelper.mockSteps(glue, stepsToResult, stepsToLocation);
TestHelper.mockHooks(glue, hooks, hookLocations, hookActions);
return glue;
Expand Down
2 changes: 1 addition & 1 deletion java/src/test/java/cucumber/runtime/java/JavaHookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class JavaHookTest {
private final SingletonFactory objectFactory = new SingletonFactory();
private final JavaBackend backend = new JavaBackend(objectFactory);
private final LocalizedXStreams localizedXStreams = new LocalizedXStreams(Thread.currentThread().getContextClassLoader());
private final Glue glue = new RuntimeGlue(new UndefinedStepsTracker(), localizedXStreams);
private final Glue glue = new RuntimeGlue(localizedXStreams);

@org.junit.Before
public void loadNoGlue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ private FeatureRunner createFeatureRunner(CucumberFeature cucumberFeature, JUnit
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final RuntimeGlue glue = mock(RuntimeGlue.class);
when(glue.getTracker()).thenReturn(new UndefinedStepsTracker());
final TimeService timeServiceStub = new TimeService() {
@Override
public long time() {
Expand Down