Skip to content

Commit b502f4e

Browse files
committed
Merge branch 'master' of github.com:cucumber/cucumber-jvm
# By Aslak Hellesøy (1) and bayrhammerklaus (1) # Via Aslak Hellesøy * 'master' of github.com:cucumber/cucumber-jvm: Attribution. Fix broken test. Closes #568 #568 Inherit Information of @Cucumber.Options
2 parents 1fc71f0 + 63b7cec commit b502f4e

File tree

3 files changed

+71
-17
lines changed

3 files changed

+71
-17
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...master)
22

3+
* [JUnit] Inherit Information of @Cucumber.Options ([#568](https://github.com/cucumber/cucumber-jvm/issues/568) Klaus Bayrhammer)
34
* [JUnit] JUnitFormatter does not put required name attribute in testsuite root element ([#480](https://github.com/cucumber/cucumber-jvm/pull/480), [#477](https://github.com/cucumber/cucumber-jvm/issues/477) ericmaxwell2003)
45
* [Core] Output embedded text in HTML report ([#501](https://github.com/cucumber/cucumber-jvm/pull/501) Tom Dunstan)
56
* [Core] Fix for Lexing Error message not useful ([#519](https://github.com/cucumber/cucumber-jvm/issues/519), [#523](https://github.com/cucumber/cucumber-jvm/pull/523) Alpar Gal)

junit/src/main/java/cucumber/runtime/junit/RuntimeOptionsFactory.java

+26-16
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,33 @@ public RuntimeOptionsFactory(Class clazz) {
1616
}
1717

1818
public RuntimeOptions create() {
19+
List<String> args = buildArgsFromOptions();
20+
21+
return new RuntimeOptions(System.getProperties(), args.toArray(new String[args.size()]));
22+
}
23+
24+
private List<String> buildArgsFromOptions() {
1925
List<String> args = new ArrayList<String>();
20-
Cucumber.Options options = getOptions(clazz);
21-
22-
addDryRun(options, args);
23-
addMonochrome(options, args);
24-
addGlue(options, args, clazz);
25-
addTags(options, args);
26-
addFormats(options, args);
27-
addFeatures(options, args, clazz);
28-
addStrict(options, args);
29-
addName(options, args);
30-
addDotCucumber(options, args);
31-
addSnippets(options, args);
32-
33-
RuntimeOptions runtimeOptions = new RuntimeOptions(System.getProperties(), args.toArray(new String[args.size()]));
34-
35-
return runtimeOptions;
26+
27+
for (Class classWithOptions = clazz; hasSuperClass(classWithOptions); classWithOptions = classWithOptions.getSuperclass()) {
28+
Cucumber.Options options = getOptions(classWithOptions);
29+
30+
addDryRun(options, args);
31+
addMonochrome(options, args);
32+
addGlue(options, args, classWithOptions);
33+
addTags(options, args);
34+
addFormats(options, args);
35+
addFeatures(options, args, classWithOptions);
36+
addStrict(options, args);
37+
addName(options, args);
38+
addDotCucumber(options, args);
39+
addSnippets(options, args);
40+
}
41+
return args;
42+
}
43+
44+
private boolean hasSuperClass(Class classWithOptions) {
45+
return classWithOptions != Object.class;
3646
}
3747

3848
private void addDotCucumber(Cucumber.Options options, List<String> args) {

junit/src/test/java/cucumber/runtime/junit/RuntimeOptionsFactoryTest.java

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package cucumber.runtime.junit;
22

3+
import cucumber.api.SnippetType;
34
import cucumber.api.junit.Cucumber;
45
import cucumber.runtime.RuntimeOptions;
5-
import cucumber.api.SnippetType;
6+
import gherkin.formatter.Formatter;
7+
import gherkin.formatter.JSONFormatter;
8+
import gherkin.formatter.PrettyFormatter;
69
import org.junit.Test;
710

811
import java.net.MalformedURLException;
@@ -94,6 +97,26 @@ public void finds_path_for_class_in_toplevel_package() {
9497
assertEquals("", packageName("TopLevelClass"));
9598
}
9699

100+
@Test
101+
public void inherit_formatter_from_baseclass() {
102+
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(SubClassWithFormatter.class);
103+
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
104+
105+
List<Formatter> formatters = runtimeOptions.getFormatters();
106+
assertEquals(2, formatters.size());
107+
assertTrue(formatters.get(0) instanceof PrettyFormatter);
108+
assertTrue(formatters.get(1) instanceof JSONFormatter);
109+
}
110+
111+
@Test
112+
public void override_monochrome_flag_from_baseclass() {
113+
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(SubClassWithMonoChromeTrue.class);
114+
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
115+
116+
assertTrue(runtimeOptions.isMonochrome());
117+
}
118+
119+
97120
@Cucumber.Options(snippets = SnippetType.CAMELCASE)
98121
static class Snippets {
99122
// empty
@@ -132,4 +155,24 @@ static class DotCucumberUrl {
132155
static class WithoutOptions {
133156
// empty
134157
}
158+
159+
@Cucumber.Options(format = "pretty")
160+
static class SubClassWithFormatter extends BaseClassWithFormatter {
161+
// empty
162+
}
163+
164+
@Cucumber.Options(format = "json:outFile")
165+
static class BaseClassWithFormatter {
166+
// empty
167+
}
168+
169+
@Cucumber.Options(monochrome = true)
170+
static class SubClassWithMonoChromeTrue extends BaseClassWithMonoChromeFalse {
171+
// empty
172+
}
173+
174+
@Cucumber.Options(monochrome = false)
175+
static class BaseClassWithMonoChromeFalse {
176+
// empty
177+
}
135178
}

0 commit comments

Comments
 (0)