Skip to content

Commit b2ac1f8

Browse files
committed
Merge branch 'master' into android
# By Aslak Hellesøy (9) and others # Via Dmytro Chyzhykov (2) and others * master: [TestNG] Java Calculator TestNG example project - #579 issue. [Jython] Access to scenario in Before and After hooks. Closes #582. Scenario Outlines: Replace tokens in the names of the generated "Example Scenario"s. Change some remaining Cucumber.Options to CucumberOptions No longer used No longer used master is SNAPSHOT Java Calculator TestNG example project. Enable Wicket example, using HtmlUnitDriver so it runs on Travis. Upgraded maven plugins. is deprecated in favour of . Closes #549 Disable wicket example for now Updated History.md with Android improvements. Ref #547 and #574. Attribution. Fix broken test. Closes #568 Enable wicket example. Removed incorrect comment about cargo requiring Java 7. It does not. (Jetty 9 does, but we're on 8 now). #568 Inherit Information of @Cucumber.Options
2 parents 18d44c1 + df3cfc9 commit b2ac1f8

File tree

41 files changed

+784
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+784
-253
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ libpeerconnection.log
3131
ehthumbs.db
3232
Icon?
3333
Thumbs.db
34+
test-json-report.json

Gemfile

-4
This file was deleted.

History.md

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

3+
* [TestNG] Java Calculator TestNG example project ([#579](https://github.com/cucumber/cucumber-jvm/pull/579) Dmytro Chyzhykov)
4+
* [Jython] Access to scenario in Before and After hooks ([#582](https://github.com/cucumber/cucumber-jvm/issues/582) Aslak Hellesøy)
5+
* [Core] Replace placeholders in the Scenario Outline title ([#580](https://github.com/cucumber/cucumber-jvm/pull/580), [#510](https://github.com/cucumber/cucumber-jvm/issues/510) Jamie W. Astin)
6+
* [JUnit/Core] `@cucumber.junit.api.Cucumber.Options` is deprecated in favour of `@cucumber.api.Options` ([#549](https://github.com/cucumber/cucumber-jvm/issues/549) Aslak Hellesøy)
7+
* [JUnit] Inherit Information of @Cucumber.Options ([#568](https://github.com/cucumber/cucumber-jvm/issues/568) Klaus Bayrhammer)
38
* [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)
49
* [Core] Output embedded text in HTML report ([#501](https://github.com/cucumber/cucumber-jvm/pull/501) Tom Dunstan)
510
* [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)
@@ -9,6 +14,7 @@
914
* [Core] Bugfix: StringIndexOutOfBoundsException when optional argument not present. ([#394](https://github.com/cucumber/cucumber-jvm/issues/394), [#558](https://github.com/cucumber/cucumber-jvm/pull/558) Guy Burton)
1015
* [Java, Jython] New `--snippet [underscore|camelcase]` option for more control over snippet style. ([#561](https://github.com/cucumber/cucumber-jvm/pull/561), [302](https://github.com/cucumber/cucumber-jvm/pull/302) Márton Mészáros, Aslak Hellesøy)
1116
* [Windows] Use uri instead of path in CucumberFeature ([#562](https://github.com/cucumber/cucumber-jvm/pull/562) Björn Rasmusson)
17+
* [Android] Better example for Cucumber-Android. ([#547](https://github.com/cucumber/cucumber-jvm/issues/547), [#574](https://github.com/cucumber/cucumber-jvm/issues/574))
1218

1319
## [1.1.4](https://github.com/cucumber/cucumber-jvm/compare/v1.1.3...v1.1.4) (2013-08-11)
1420

Rakefile

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package cucumber.api;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* This annotation provides the same options as the cucumber command line, {@link cucumber.api.cli.Main}.
10+
*/
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target({ElementType.TYPE})
13+
public @interface CucumberOptions {
14+
/**
15+
* @return true if this is a dry run
16+
*/
17+
boolean dryRun() default false;
18+
19+
/**
20+
* @return true if strict mode is enabled (fail if there are undefined or pending steps)
21+
*/
22+
boolean strict() default false;
23+
24+
/**
25+
* @return the paths to the feature(s)
26+
*/
27+
String[] features() default {};
28+
29+
/**
30+
* @return where to look for glue code (stepdefs and hooks)
31+
*/
32+
String[] glue() default {};
33+
34+
/**
35+
* @return what tags in the features should be executed
36+
*/
37+
String[] tags() default {};
38+
39+
/**
40+
* @return what formatter(s) to use
41+
*/
42+
String[] format() default {};
43+
44+
/**
45+
* @return whether or not to use monochrome output
46+
*/
47+
boolean monochrome() default false;
48+
49+
/**
50+
* Specify a patternfilter for features or scenarios
51+
*
52+
* @return a list of patterns
53+
*/
54+
String[] name() default {};
55+
56+
String dotcucumber() default "";
57+
58+
/**
59+
* @return what format should the snippets use. underscore, camelcase
60+
*/
61+
SnippetType snippets() default SnippetType.UNDERSCORE;
62+
}

core/src/main/java/cucumber/api/Scenario.java

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* It allows writing text and embedding media into reports, as well as inspecting results (in an After block).
88
*/
99
public interface Scenario {
10+
/**
11+
* @return source_tag_names. Needed for compatibility with Capybara.
12+
*/
1013
Collection<String> getSourceTagNames();
1114

1215
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
package cucumber.runtime;
2+
3+
import cucumber.api.SnippetType;
4+
import cucumber.runtime.io.MultiLoader;
5+
6+
import java.lang.annotation.Annotation;
7+
import java.lang.reflect.InvocationTargetException;
8+
import java.lang.reflect.Method;
9+
import java.util.ArrayList;
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
public class RuntimeOptionsFactory {
14+
private final Class clazz;
15+
private final Class<? extends Annotation>[] annotationClasses;
16+
17+
public RuntimeOptionsFactory(Class clazz, Class<? extends Annotation>[] annotationClasses) {
18+
this.clazz = clazz;
19+
this.annotationClasses = annotationClasses;
20+
}
21+
22+
public RuntimeOptions create() {
23+
List<String> args = buildArgsFromOptions();
24+
25+
return new RuntimeOptions(System.getProperties(), args.toArray(new String[args.size()]));
26+
}
27+
28+
private List<String> buildArgsFromOptions() {
29+
List<String> args = new ArrayList<String>();
30+
31+
for (Class classWithOptions = clazz; hasSuperClass(classWithOptions); classWithOptions = classWithOptions.getSuperclass()) {
32+
Annotation[] optionsArray = getOptions(classWithOptions);
33+
for (Annotation options : optionsArray) {
34+
if (options != null) {
35+
addDryRun(options, args);
36+
addMonochrome(options, args);
37+
addTags(options, args);
38+
addFormats(options, args);
39+
addStrict(options, args);
40+
addName(options, args);
41+
addDotCucumber(options, args);
42+
addSnippets(options, args);
43+
}
44+
}
45+
addGlue(optionsArray, args, classWithOptions);
46+
addFeatures(optionsArray, args, classWithOptions);
47+
}
48+
return args;
49+
}
50+
51+
private void addDotCucumber(Annotation options, List<String> args) {
52+
String dotcucumber = this.invoke(options, "dotcucumber");
53+
if (!dotcucumber.isEmpty()) {
54+
args.add("--dotcucumber");
55+
args.add(dotcucumber);
56+
}
57+
}
58+
59+
private void addName(Annotation options, List<String> args) {
60+
for (String name : this.<String[]>invoke(options, "name")) {
61+
args.add("--name");
62+
args.add(name);
63+
}
64+
}
65+
66+
private void addSnippets(Annotation options, List<String> args) {
67+
args.add("--snippets");
68+
args.add(this.<SnippetType>invoke(options, "snippets").toString());
69+
}
70+
71+
private void addDryRun(Annotation options, List<String> args) {
72+
if (this.<Boolean>invoke(options, "dryRun")) {
73+
args.add("--dry-run");
74+
}
75+
}
76+
77+
private void addMonochrome(Annotation options, List<String> args) {
78+
if (this.<Boolean>invoke(options, "monochrome") || runningInEnvironmentWithoutAnsiSupport()) {
79+
args.add("--monochrome");
80+
}
81+
}
82+
83+
private void addTags(Annotation options, List<String> args) {
84+
for (String tags : this.<String[]>invoke(options, "tags")) {
85+
args.add("--tags");
86+
args.add(tags);
87+
}
88+
}
89+
90+
private void addFormats(Annotation options, List<String> args) {
91+
if (this.<String[]>invoke(options, "format").length != 0) {
92+
for (String format : this.<String[]>invoke(options, "format")) {
93+
args.add("--format");
94+
args.add(format);
95+
}
96+
} else {
97+
args.add("--format");
98+
args.add("null");
99+
}
100+
}
101+
102+
private void addFeatures(Annotation[] optionsArray, List<String> args, Class clazz) {
103+
boolean specified = false;
104+
for (Annotation options : optionsArray) {
105+
if (options != null && this.<String[]>invoke(options, "features").length != 0) {
106+
Collections.addAll(args, this.<String[]>invoke(options, "features"));
107+
specified = true;
108+
}
109+
}
110+
if (!specified) {
111+
args.add(MultiLoader.CLASSPATH_SCHEME + packagePath(clazz));
112+
}
113+
}
114+
115+
private void addGlue(Annotation[] optionsArray, List<String> args, Class clazz) {
116+
boolean specified = false;
117+
for (Annotation options : optionsArray) {
118+
if (options != null && this.<String[]>invoke(options, "glue").length != 0) {
119+
for (String glue : this.<String[]>invoke(options, "glue")) {
120+
args.add("--glue");
121+
args.add(glue);
122+
}
123+
specified = true;
124+
}
125+
}
126+
if (!specified) {
127+
args.add("--glue");
128+
args.add(MultiLoader.CLASSPATH_SCHEME + packagePath(clazz));
129+
}
130+
}
131+
132+
133+
private void addStrict(Annotation options, List<String> args) {
134+
if (this.<Boolean>invoke(options, "strict")) {
135+
args.add("--strict");
136+
}
137+
}
138+
139+
static String packagePath(Class clazz) {
140+
return packagePath(packageName(clazz.getName()));
141+
}
142+
143+
static String packagePath(String packageName) {
144+
return packageName.replace('.', '/');
145+
}
146+
147+
static String packageName(String className) {
148+
return className.substring(0, Math.max(0, className.lastIndexOf(".")));
149+
}
150+
151+
private boolean runningInEnvironmentWithoutAnsiSupport() {
152+
boolean intelliJidea = System.getProperty("idea.launcher.bin.path") != null;
153+
// TODO: What does Eclipse use?
154+
return intelliJidea;
155+
}
156+
157+
private boolean hasSuperClass(Class classWithOptions) {
158+
return classWithOptions != Object.class;
159+
}
160+
161+
private Annotation[] getOptions(Class<?> clazz) {
162+
Annotation[] annotations = new Annotation[annotationClasses.length];
163+
for (int i = 0; i < annotations.length; i++) {
164+
annotations[i] = clazz.getAnnotation(annotationClasses[i]);
165+
}
166+
return annotations;
167+
}
168+
169+
private <T> T invoke(Annotation options, String name) {
170+
try {
171+
Method method = options.annotationType().getMethod(name);
172+
return (T) method.invoke(options);
173+
} catch (NoSuchMethodException e) {
174+
throw new CucumberException(e);
175+
} catch (InvocationTargetException e) {
176+
throw new CucumberException(e);
177+
} catch (IllegalAccessException e) {
178+
throw new CucumberException(e);
179+
}
180+
}
181+
182+
}

core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
4848
}
4949

5050
CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
51-
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), getGherkinModel().getName(), "", example.getLine(), example.getId());
51+
// Make sure we replace the tokens in the name of the scenario
52+
String exampleScenarioName = replaceTokens(new HashSet<Integer>(), header.getCells(), example.getCells(), getGherkinModel().getName());
53+
54+
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), exampleScenarioName, "", example.getLine(), example.getId());
5255
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
5356
for (Step step : getSteps()) {
5457
cucumberScenario.step(createExampleStep(step, header, example));

0 commit comments

Comments
 (0)