Skip to content

Commit af64ab2

Browse files
committed
Ignore duplicate features instead of throwing exception. Closes #259.
1 parent 21e0f2b commit af64ab2

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
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.0.0.RC20...master)
22

3+
* [Core] Ignore duplicate features instead of throwing exception. ([#259](https://github.com/cucumber/cucumber-jvm/issues/259) Aslak Hellesøy)
34
* [Core] Wrong message when runner on a non existing tag on feature ([#245](https://github.com/cucumber/cucumber-jvm/issues/245) Aslak Hellesøy, Jérémy Goupil)
45
* [Groovy, Groovy, JRuby, Rhino] Make sure UTF-8 encoding is used everywhere ([#251](https://github.com/cucumber/cucumber-jvm/issues/251) Aslak Hellesøy)
56
* [Core, Cloure] Fixed StepDefinitionMatch to work with StepDefinitions that return null for getParameterTypes ([#250](https://github.com/cucumber/cucumber-jvm/issues/250), [#255](https://github.com/cucumber/cucumber-jvm/pull/255) Nils Wloka)

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,21 @@ public void close() {
9494
}
9595

9696
public void parse(Resource resource, List<Object> filters) {
97-
Formatter formatter = this;
98-
if (!filters.isEmpty()) {
99-
formatter = new FilterFormatter(this, filters);
100-
}
101-
Parser parser = new Parser(formatter);
10297
String gherkin = read(resource);
10398

10499
String checksum = checksum(gherkin);
105100
String path = pathsByChecksum.get(checksum);
106101
if (path != null) {
107-
throw new CucumberException(String.format("Found the same source in %s and %s", path, resource.getPath()));
102+
return;
108103
}
109104
pathsByChecksum.put(checksum, resource.getPath());
110105

106+
Formatter formatter = this;
107+
if (!filters.isEmpty()) {
108+
formatter = new FilterFormatter(this, filters);
109+
}
110+
Parser parser = new Parser(formatter);
111+
111112
parser.parse(gherkin, resource.getPath(), 0);
112113
I18n i18n = parser.getI18nLanguage();
113114
if (currentCucumberFeature != null) {

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@
1010
import java.util.List;
1111

1212
import static java.util.Collections.emptyList;
13+
import static org.junit.Assert.assertEquals;
1314
import static org.mockito.Mockito.mock;
1415
import static org.mockito.Mockito.when;
1516

1617
public class FeatureBuilderTest {
17-
@Test(expected = CucumberException.class)
18-
public void detects_duplicate_features() throws IOException {
19-
List<CucumberFeature> fearures = new ArrayList<CucumberFeature>();
20-
FeatureBuilder builder = new FeatureBuilder(fearures);
18+
19+
public static final List<Object> NO_FILTERS = emptyList();
20+
21+
@Test
22+
public void ignores_duplicate_features() throws IOException {
23+
List<CucumberFeature> features = new ArrayList<CucumberFeature>();
24+
FeatureBuilder builder = new FeatureBuilder(features);
2125
Resource resource = mock(Resource.class);
2226
when(resource.getPath()).thenReturn("foo.feature");
2327
ByteArrayInputStream firstFeature = new ByteArrayInputStream("Feature: foo".getBytes("UTF-8"));
2428
ByteArrayInputStream secondFeature = new ByteArrayInputStream("Feature: foo".getBytes("UTF-8"));
2529
when(resource.getInputStream()).thenReturn(firstFeature, secondFeature);
26-
builder.parse(resource, emptyList());
27-
builder.parse(resource, emptyList());
30+
builder.parse(resource, NO_FILTERS);
31+
builder.parse(resource, NO_FILTERS);
32+
assertEquals(1, features.size());
2833
}
2934

3035
}

0 commit comments

Comments
 (0)