Skip to content

Commit e01977a

Browse files
committed
Use "uri" instead of "path" to reference feature files.
Using "uri" is used in the Gherkin library, and has also the advantage of that uri:s use the same separator, "/", on all platforms, whereas path:s use different separators, "/" on Unix/Linux and MacOS, but "\" in Windows.
1 parent fde271e commit e01977a

File tree

19 files changed

+48
-48
lines changed

19 files changed

+48
-48
lines changed

android/src/main/java/cucumber/runtime/android/AndroidInstrumentationReporter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ public void setNumberOfTests(final int numberOfTests) {
163163
}
164164

165165
void testSourceRead(final TestSourceRead event) {
166-
testSources.addTestSourceReadEvent(event.path, event);
166+
testSources.addTestSourceReadEvent(event.uri, event);
167167
}
168168

169169
void startTestCase(final TestCase testCase) {
170-
if (!testCase.getPath().equals(currentUri)) {
171-
currentUri = testCase.getPath();
170+
if (!testCase.getUri().equals(currentUri)) {
171+
currentUri = testCase.getUri();
172172
currentFeatureName = testSources.getFeatureName(currentUri);
173173
}
174174
currentTestCaseName = testCase.getName();

android/src/test/java/cucumber/runtime/android/AndroidInstrumentationReporterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class AndroidInstrumentationReporterTest {
5050

5151
@Before
5252
public void beforeEachTest() {
53-
when(testCase.getPath()).thenReturn("path/file.feature");
53+
when(testCase.getUri()).thenReturn("path/file.feature");
5454
when(testCase.getName()).thenReturn("Some important scenario");
5555
}
5656

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
boolean strict() default false;
2323

2424
/**
25-
* @return the paths to the feature(s)
25+
* @return the uris to the feature(s)
2626
*/
2727
String[] features() default {};
2828

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public String getScenarioDesignation() {
4747
return fileColonLine(pickleEvent.pickle.getLocations().get(0)) + " # " + getName();
4848
}
4949

50-
public String getPath() {
50+
public String getUri() {
5151
return pickleEvent.uri;
5252
}
5353

core/src/main/java/cucumber/api/event/TestSourceRead.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package cucumber.api.event;
22

33
public final class TestSourceRead extends TimeStampedEvent {
4-
public final String path;
4+
public final String uri;
55
public final String language;
66
public final String source;
77

8-
public TestSourceRead(Long timeStamp, String path, String language, String source) {
8+
public TestSourceRead(Long timeStamp, String uri, String language, String source) {
99
super(timeStamp);
10-
this.path = path;
10+
this.uri = uri;
1111
this.language = language;
1212
this.source = source;
1313
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void runFeature(CucumberFeature feature) {
124124
public List<PickleEvent> compileFeature(CucumberFeature feature) {
125125
List<PickleEvent> pickleEvents = new ArrayList<PickleEvent>();
126126
for (Pickle pickle : compiler.compile(feature.getGherkinFeature())) {
127-
pickleEvents.add(new PickleEvent(feature.getPath(), pickle));
127+
pickleEvents.add(new PickleEvent(feature.getUri(), pickle));
128128
}
129129
return pickleEvents;
130130
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class UndefinedStepsTracker implements EventListener {
3333
private EventHandler<TestSourceRead> testSourceReadHandler = new EventHandler<TestSourceRead>() {
3434
@Override
3535
public void receive(TestSourceRead event) {
36-
pathToSourceMap.put(event.path, event.source);
36+
pathToSourceMap.put(event.uri, event.source);
3737
}
3838
};
3939
private EventHandler<SnippetsSuggestedEvent> snippetsSuggestedHandler = new EventHandler<SnippetsSuggestedEvent>() {

core/src/main/java/cucumber/runtime/formatter/HTMLFormatter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void setEventPublisher(EventPublisher publisher) {
140140
}
141141

142142
private void handleTestSourceRead(TestSourceRead event) {
143-
testSources.addTestSourceReadEvent(event.path, event);
143+
testSources.addTestSourceReadEvent(event.uri, event);
144144
}
145145

146146
private void handleTestCaseStarted(TestCaseStarted event) {
@@ -208,16 +208,16 @@ private void finishReport() {
208208
}
209209

210210
private void handleStartOfFeature(TestCase testCase) {
211-
if (currentFeatureFile == null || !currentFeatureFile.equals(testCase.getPath())) {
212-
currentFeatureFile = testCase.getPath();
211+
if (currentFeatureFile == null || !currentFeatureFile.equals(testCase.getUri())) {
212+
currentFeatureFile = testCase.getUri();
213213
jsFunctionCall("uri", currentFeatureFile);
214214
jsFunctionCall("feature", createFeature(testCase));
215215
}
216216
}
217217

218218
private Map<String, Object> createFeature(TestCase testCase) {
219219
Map<String, Object> featureMap = new HashMap<String, Object>();
220-
Feature feature = testSources.getFeature(testCase.getPath());
220+
Feature feature = testSources.getFeature(testCase.getUri());
221221
if (feature != null) {
222222
featureMap.put("keyword", feature.getKeyword());
223223
featureMap.put("name", feature.getName());

core/src/main/java/cucumber/runtime/formatter/JSONFormatter.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ public void setEventPublisher(EventPublisher publisher) {
105105
}
106106

107107
private void handleTestSourceRead(TestSourceRead event) {
108-
testSources.addTestSourceReadEvent(event.path, event);
108+
testSources.addTestSourceReadEvent(event.uri, event);
109109
}
110110

111111
private void handleTestCaseStarted(TestCaseStarted event) {
112-
if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getPath())) {
113-
currentFeatureFile = event.testCase.getPath();
112+
if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getUri())) {
113+
currentFeatureFile = event.testCase.getUri();
114114
Map<String, Object> currentFeatureMap = createFeatureMap(event.testCase);
115115
featureMaps.add(currentFeatureMap);
116116
currentElementsList = (List<Map<String, Object>>) currentFeatureMap.get("elements");
@@ -160,9 +160,9 @@ private void finishReport() {
160160

161161
private Map<String, Object> createFeatureMap(TestCase testCase) {
162162
Map<String, Object> featureMap = new HashMap<String, Object>();
163-
featureMap.put("uri", testCase.getPath());
163+
featureMap.put("uri", testCase.getUri());
164164
featureMap.put("elements", new ArrayList<Map<String, Object>>());
165-
Feature feature = testSources.getFeature(testCase.getPath());
165+
Feature feature = testSources.getFeature(testCase.getUri());
166166
if (feature != null) {
167167
featureMap.put("keyword", feature.getKeyword());
168168
featureMap.put("name", feature.getName());

core/src/main/java/cucumber/runtime/formatter/JUnitFormatter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ public void setEventPublisher(EventPublisher publisher) {
106106
}
107107

108108
private void handleTestSourceRead(TestSourceRead event) {
109-
TestCase.testSources.addTestSourceReadEvent(event.path, event);
109+
TestCase.testSources.addTestSourceReadEvent(event.uri, event);
110110
}
111111

112112
private void handleTestCaseStarted(TestCaseStarted event) {
113-
if (TestCase.currentFeatureFile == null || !TestCase.currentFeatureFile.equals(event.testCase.getPath())) {
114-
TestCase.currentFeatureFile = event.testCase.getPath();
113+
if (TestCase.currentFeatureFile == null || !TestCase.currentFeatureFile.equals(event.testCase.getUri())) {
114+
TestCase.currentFeatureFile = event.testCase.getUri();
115115
TestCase.previousTestCaseName = "";
116116
TestCase.exampleNumber = 1;
117117
}

core/src/main/java/cucumber/runtime/formatter/PrettyFormatter.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void setMonochrome(boolean monochrome) {
115115
}
116116

117117
private void handleTestSourceRead(TestSourceRead event) {
118-
testSources.addTestSourceReadEvent(event.path, event);
118+
testSources.addTestSourceReadEvent(event.uri, event);
119119
}
120120

121121
private void handleTestCaseStarted(TestCaseStarted event) {
@@ -155,11 +155,11 @@ private void finishReport() {
155155
}
156156

157157
private void handleStartOfFeature(TestCaseStarted event) {
158-
if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getPath())) {
158+
if (currentFeatureFile == null || !currentFeatureFile.equals(event.testCase.getUri())) {
159159
if (currentFeatureFile != null) {
160160
out.println();
161161
}
162-
currentFeatureFile = event.testCase.getPath();
162+
currentFeatureFile = event.testCase.getUri();
163163
printFeature(currentFeatureFile);
164164
}
165165
}

core/src/main/java/cucumber/runtime/formatter/RerunFormatter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void handleTestRunFinished() {
6464
}
6565

6666
private void recordTestFailed(TestCase testCase) {
67-
String path = testCase.getPath();
67+
String path = testCase.getUri();
6868
ArrayList<Integer> failedTestCases = this.featureAndFailedLinesMapping.get(path);
6969
if (failedTestCases == null) {
7070
failedTestCases = new ArrayList<Integer>();

core/src/main/java/cucumber/runtime/formatter/TestNGFormatter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ public void setStrict(boolean strict) {
116116
}
117117

118118
private void handleTestSourceRead(TestSourceRead event) {
119-
TestMethod.testSources.addTestSourceReadEvent(event.path, event);
119+
TestMethod.testSources.addTestSourceReadEvent(event.uri, event);
120120
}
121121

122122
private void handleTestCaseStarted(TestCaseStarted event) {
123-
if (TestMethod.currentFeatureFile == null || !TestMethod.currentFeatureFile.equals(event.testCase.getPath())) {
124-
TestMethod.currentFeatureFile = event.testCase.getPath();
123+
if (TestMethod.currentFeatureFile == null || !TestMethod.currentFeatureFile.equals(event.testCase.getUri())) {
124+
TestMethod.currentFeatureFile = event.testCase.getUri();
125125
TestMethod.previousTestCaseName = "";
126126
TestMethod.exampleNumber = 1;
127127
clazz = document.createElement("class");
128-
clazz.setAttribute("name", TestMethod.testSources.getFeature(event.testCase.getPath()).getName());
128+
clazz.setAttribute("name", TestMethod.testSources.getFeature(event.testCase.getUri()).getName());
129129
test.appendChild(clazz);
130130
}
131131
root = document.createElement("test-method");

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
public class CucumberFeature implements Serializable {
2323
private static final long serialVersionUID = 1L;
24-
private final String path;
24+
private final String uri;
2525
private String language;
2626
private GherkinDocument gherkinDocument;
2727
private String gherkinSource;
@@ -117,9 +117,9 @@ private static void loadFromFeaturePath(FeatureBuilder builder, ResourceLoader r
117117
}
118118
}
119119

120-
public CucumberFeature(GherkinDocument gherkinDocument, String path, String gherkinSource) {
120+
public CucumberFeature(GherkinDocument gherkinDocument, String uri, String gherkinSource) {
121121
this.gherkinDocument = gherkinDocument;
122-
this.path = path;
122+
this.uri = uri;
123123
this.gherkinSource = gherkinSource;
124124
if (gherkinDocument.getFeature() != null) {
125125
setLanguage(gherkinDocument.getFeature().getLanguage());
@@ -134,12 +134,12 @@ public String getLanguage() {
134134
return language;
135135
}
136136

137-
public String getPath() {
138-
return path;
137+
public String getUri() {
138+
return uri;
139139
}
140140

141141
public void sendTestSourceRead(EventBus bus) {
142-
bus.send(new TestSourceRead(bus.getTime(), path, gherkinDocument.getFeature().getLanguage(), gherkinSource));
142+
bus.send(new TestSourceRead(bus.getTime(), uri, gherkinDocument.getFeature().getLanguage(), gherkinSource));
143143
}
144144

145145
private void setLanguage(String language) {
@@ -149,7 +149,7 @@ private void setLanguage(String language) {
149149
private static class CucumberFeatureUriComparator implements Comparator<CucumberFeature> {
150150
@Override
151151
public int compare(CucumberFeature a, CucumberFeature b) {
152-
return a.getPath().compareTo(b.getPath());
152+
return a.getUri().compareTo(b.getUri());
153153
}
154154
}
155155
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void works_when_path_and_uri_are_the_same() throws IOException {
4040
builder.parse(resource);
4141

4242
assertEquals(1, features.size());
43-
assertEquals(featurePath, features.get(0).getPath());
43+
assertEquals(featurePath, features.get(0).getUri());
4444
}
4545

4646
@Test
@@ -54,7 +54,7 @@ public void converts_windows_path_to_forward_slash() throws IOException {
5454
builder.parse(resource);
5555

5656
assertEquals(1, features.size());
57-
assertEquals("path/foo.feature", features.get(0).getPath());
57+
assertEquals("path/foo.feature", features.get(0).getUri());
5858
}
5959

6060
private Resource createResourceMock(String featurePath) throws IOException {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void buildFeatureElementRunners(Runtime runtime, JUnitReporter jUnitRepo
7777
Compiler compiler = new Compiler();
7878
List<PickleEvent> pickleEvents = new ArrayList<PickleEvent>();
7979
for (Pickle pickle : compiler.compile(cucumberFeature.getGherkinFeature())) {
80-
pickleEvents.add(new PickleEvent(cucumberFeature.getPath(), pickle));
80+
pickleEvents.add(new PickleEvent(cucumberFeature.getUri(), pickle));
8181
}
8282
Feature feature = cucumberFeature.getGherkinFeature().getFeature();
8383
String featureName = feature.getName();
@@ -105,7 +105,7 @@ private static final class FeatureId implements Serializable {
105105
private final String uri;
106106

107107
FeatureId(CucumberFeature feature) {
108-
this.uri = feature.getPath();
108+
this.uri = feature.getUri();
109109
}
110110

111111
@Override

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void shouldAssignUnequalDescriptionsToDifferentOccurrencesOfSameStepInASc
4040
Compiler compiler = new Compiler();
4141
List<PickleEvent> pickleEvents = new ArrayList<PickleEvent>();
4242
for (Pickle pickle : compiler.compile(features.getGherkinFeature())) {
43-
pickleEvents.add(new PickleEvent(features.getPath(), pickle));
43+
pickleEvents.add(new PickleEvent(features.getUri(), pickle));
4444
};
4545

4646
WithStepDescriptions runner = (WithStepDescriptions) PickleRunners.withStepDescriptions(
@@ -78,7 +78,7 @@ public void shouldAssignUnequalDescriptionsToDifferentStepsInAScenarioOutline()
7878
Compiler compiler = new Compiler();
7979
List<PickleEvent> pickleEvents = new ArrayList<PickleEvent>();
8080
for (Pickle pickle : compiler.compile(features.getGherkinFeature())) {
81-
pickleEvents.add(new PickleEvent(features.getPath(), pickle));
81+
pickleEvents.add(new PickleEvent(features.getUri(), pickle));
8282
};
8383

8484
WithStepDescriptions runner = (WithStepDescriptions) PickleRunners.withStepDescriptions(
@@ -110,7 +110,7 @@ public void shouldIncludeScenarioNameAsClassNameInStepDescriptions() throws Exce
110110
Compiler compiler = new Compiler();
111111
List<PickleEvent> pickleEvents = new ArrayList<PickleEvent>();
112112
for (Pickle pickle : compiler.compile(features.getGherkinFeature())) {
113-
pickleEvents.add(new PickleEvent(features.getPath(), pickle));
113+
pickleEvents.add(new PickleEvent(features.getUri(), pickle));
114114
}
115115

116116
PickleRunner runner = PickleRunners.withStepDescriptions(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static List<PickleEvent> pickleEventsFromFeature(final String path, final String
2323

2424
CucumberFeature feature = parseFeature(path, source);
2525
for (Pickle pickle : compiler.compile(feature.getGherkinFeature())) {
26-
pickleEvents.add(new PickleEvent(feature.getPath(), pickle));
26+
pickleEvents.add(new PickleEvent(feature.getUri(), pickle));
2727
};
2828
return pickleEvents;
2929
}

testng/src/main/java/cucumber/api/testng/TestNGCucumberRunner.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void close() {
6060
public void runCukes() {
6161
System.err.println("WARNING: The TestNGCucumberRunner.runCukes() is deprecated. Please create a runner class by subclassing AbstractTestNGCucumberTest.");
6262
for (CucumberFeature cucumberFeature : getFeatures()) {
63-
reporter.uri(cucumberFeature.getPath());
63+
reporter.uri(cucumberFeature.getUri());
6464
runtime.runFeature(cucumberFeature);
6565
}
6666
finish();
@@ -71,7 +71,7 @@ public void runCukes() {
7171

7272
public void runCucumber(CucumberFeature cucumberFeature) {
7373
resultListener.startFeature();
74-
reporter.uri(cucumberFeature.getPath());
74+
reporter.uri(cucumberFeature.getUri());
7575
runtime.runFeature(cucumberFeature);
7676

7777
if (!resultListener.isPassed()) {

0 commit comments

Comments
 (0)