Skip to content

Commit

Permalink
Merge cucumber#842. Update History.md
Browse files Browse the repository at this point in the history
Merge cucumber#842 "Call all formatters, also when using the IntelliJ's
internal formatter."
  • Loading branch information
brasmusson committed Mar 18, 2015
2 parents d4f69c6 + 1e573f5 commit 3a7a8a9
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 13 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [1.2.3-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.2...master) (In Git)

* [Core] Call all formatters, also in case of unimplemented methods ([#842](https://github.com/cucumber/cucumber-jvm/pull/842), [#803](https://github.com/cucumber/cucumber-jvm/issues/803) Björn Rasmusson)
* [TestNG] Run each feature as separate TestNG test ([#817](https://github.com/cucumber/cucumber-jvm/pull/817), [#653](https://github.com/cucumber/cucumber-jvm/pull/653) Dmitry Sidorenko, Björn Rasmusson)
* [Core] Implement TestNG-compatible XML formatter ([#818](https://github.com/cucumber/cucumber-jvm/pull/818), [#621](https://github.com/cucumber/cucumber-jvm/pull/621) Dimitry Berezhony, Björn Rasmusson)
* `DataTable.diff(List)` gives proper error message when the `List` argument is empty (Aslak Hellesøy)
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,14 @@ public <T> T pluginProxy(ClassLoader classLoader, final Class<T> type) {
public Object invoke(Object target, Method method, Object[] args) throws Throwable {
for (Object plugin : getPlugins()) {
if (type.isInstance(plugin)) {
Utils.invoke(plugin, method, 0, args);
try {
Utils.invoke(plugin, method, 0, args);
} catch (Throwable t) {
if (!method.getName().equals("startOfScenarioLifeCycle") && !method.getName().equals("endOfScenarioLifeCycle")) {
// IntelliJ has its own formatter which doesn't yet implement these methods.
throw t;
}
}
}
}
return null;
Expand Down
12 changes: 2 additions & 10 deletions core/src/main/java/cucumber/runtime/model/CucumberScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,15 @@ public CucumberBackground getCucumberBackground() {
public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
Set<Tag> tags = tagsAndInheritedTags();
runtime.buildBackendWorlds(reporter, tags, scenario);
try {
formatter.startOfScenarioLifeCycle((Scenario) getGherkinModel());
} catch (Throwable ignore) {
// IntelliJ has its own formatter which doesn't yet implement this.
}
formatter.startOfScenarioLifeCycle((Scenario) getGherkinModel());
runtime.runBeforeHooks(reporter, tags);

runBackground(formatter, reporter, runtime);
format(formatter);
runSteps(reporter, runtime);

runtime.runAfterHooks(reporter, tags);
try {
formatter.endOfScenarioLifeCycle((Scenario) getGherkinModel());
} catch (Throwable ignore) {
// IntelliJ has its own formatter which doesn't yet implement this.
}
formatter.endOfScenarioLifeCycle((Scenario) getGherkinModel());
runtime.disposeBackendWorlds();
}

Expand Down
124 changes: 122 additions & 2 deletions core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package cucumber.runtime;

import gherkin.formatter.Reporter;
import gherkin.formatter.model.Background;
import gherkin.formatter.model.Examples;
import gherkin.formatter.model.Feature;
import gherkin.formatter.model.Match;
import gherkin.formatter.model.Result;
import gherkin.formatter.model.ScenarioOutline;
import gherkin.formatter.model.Step;
import cucumber.runtime.formatter.FormatterSpy;
import cucumber.api.SnippetType;
import cucumber.runtime.formatter.ColorAware;
import cucumber.runtime.formatter.PluginFactory;
Expand All @@ -13,10 +22,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -296,6 +304,35 @@ public void applies_line_filters_only_to_own_feature() throws Exception {
assertOnlyScenarioName(features.get(1), "scenario_2_2");
}

@Test
public void handles_formatters_missing_startOfScenarioLifeCycle_endOfScenarioLifeCycle() throws Throwable {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
"Feature: feature name\n" +
" Scenario: scenario name\n" +
" Given step\n");

FormatterSpy formatterSpy = new FormatterSpy();
RuntimeOptions runtimeOptions = new RuntimeOptions("");
runtimeOptions.addPlugin(new FormatterMissingLifecycleMethods());
runtimeOptions.addPlugin(formatterSpy);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
TestHelper.runFeatureWithFormatter(feature, new HashMap<String, String>(),
runtimeOptions.formatter(classLoader), runtimeOptions.reporter(classLoader));

assertEquals("" +
"uri\n" +
"feature\n" +
" startOfScenarioLifeCycle\n" +
" scenario\n" +
" step\n" +
" match\n" +
" result\n" +
" endOfScenarioLifeCycle\n" +
"eof\n" +
"done\n" +
"close\n", formatterSpy.toString());
}

private void assertOnlyScenarioName(CucumberFeature feature, String scenarioName) {
assertEquals("Wrong number of scenarios loaded for feature", 1, feature.getFeatureElements().size());
assertEquals("Scenario: " + scenarioName, feature.getFeatureElements().get(0).getVisualName());
Expand All @@ -309,3 +346,86 @@ private void mockResource(ResourceLoader resourceLoader, String featurePath, Str
when(resourceLoader.resources(featurePath, ".feature")).thenReturn(asList(resource1));
}
}

class FormatterMissingLifecycleMethods implements Formatter, Reporter {
@Override
public void startOfScenarioLifeCycle(gherkin.formatter.model.Scenario arg0) {
throw new NoSuchMethodError(); // simulate that this method is not implemented
}

@Override
public void endOfScenarioLifeCycle(gherkin.formatter.model.Scenario arg0) {
throw new NoSuchMethodError(); // simulate that this method is not implemented
}

@Override
public void after(Match arg0, Result arg1) {
}

@Override
public void before(Match arg0, Result arg1) {
}

@Override
public void embedding(String arg0, byte[] arg1) {
}

@Override
public void match(Match arg0) {
}

@Override
public void result(Result arg0) {
}

@Override
public void write(String arg0) {
}

@Override
public void background(Background arg0) {
}

@Override
public void close() {
}

@Override
public void done() {
}

@Override
public void eof() {
}

@Override
public void examples(Examples arg0) {
}

@Override
public void feature(Feature arg0) {

}

@Override
public void scenario(gherkin.formatter.model.Scenario arg0) {

}

@Override
public void scenarioOutline(ScenarioOutline arg0) {
}

@Override
public void step(Step arg0) {
}

@Override
public void syntaxError(String arg0, String arg1, List<String> arg2, String arg3, Integer arg4) {
}

@Override
public void uri(String arg0) {
}

}

0 comments on commit 3a7a8a9

Please sign in to comment.