Skip to content

Commit 15345c4

Browse files
committed
Add test
1 parent 8abba23 commit 15345c4

9 files changed

+142
-66
lines changed

java/src/main/java/io/cucumber/query/FirstLocationCollector.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

java/src/main/java/io/cucumber/query/Query.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ public <T> Optional<T> reduceLinageOf(Pickle pickle, LineageReducer<T> reducer)
301301
}
302302

303303
public Optional<Location> findLocationOf(Pickle pickle) {
304-
return reduceLinageOf(pickle, ascending(FirstLocationCollector::new));
304+
return findLineageBy(pickle).flatMap(lineage -> {
305+
if (lineage.example().isPresent()) {
306+
return lineage.example().map(TableRow::getLocation);
307+
}
308+
return lineage.scenario().map(Scenario::getLocation);
309+
});
305310
}
306311

307312
public Optional<Pickle> findPickleBy(TestCaseStarted testCaseStarted) {

java/src/test/java/io/cucumber/query/QueryAcceptanceTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ private static Map<String, Object> createQueryResults(Query query) {
137137
.map(hook -> hook.map(Hook::getId))
138138
.filter(Optional::isPresent)
139139
.collect(toList()));
140+
results.put("findLocationBy", query.findAllPickles().stream()
141+
.map(query::findLocationOf)
142+
.filter(Optional::isPresent)
143+
.collect(toList()));
140144
results.put("findMeta", query.findMeta().map(meta -> meta.getImplementation().getName()));
141145
results.put("findMostSevereTestStepResultBy", query.findAllTestCaseStarted().stream()
142146
.map(query::findMostSevereTestStepResultBy)

testdata/attachments.feature.query-results.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,52 @@
112112
"Attachments",
113113
"Attachments"
114114
],
115+
"findLocationBy" : [
116+
{
117+
"line" : 12,
118+
"column" : 3
119+
},
120+
{
121+
"line" : 18,
122+
"column" : 3
123+
},
124+
{
125+
"line" : 21,
126+
"column" : 3
127+
},
128+
{
129+
"line" : 24,
130+
"column" : 3
131+
},
132+
{
133+
"line" : 30,
134+
"column" : 3
135+
},
136+
{
137+
"line" : 33,
138+
"column" : 3
139+
},
140+
{
141+
"line" : 36,
142+
"column" : 3
143+
},
144+
{
145+
"line" : 44,
146+
"column" : 7
147+
},
148+
{
149+
"line" : 45,
150+
"column" : 7
151+
},
152+
{
153+
"line" : 47,
154+
"column" : 3
155+
},
156+
{
157+
"line" : 50,
158+
"column" : 3
159+
}
160+
],
115161
"findMeta" : "fake-cucumber",
116162
"findMostSevereTestStepResultBy" : [
117163
"PASSED",

testdata/empty.feature.query-results.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"findFeatureBy" : [
2525
"Empty Scenarios"
2626
],
27+
"findLocationBy" : [
28+
{
29+
"line" : 7,
30+
"column" : 3
31+
}
32+
],
2733
"findMeta" : "fake-cucumber",
2834
"findMostSevereTestStepResultBy" : [
2935
null

testdata/examples-tables.feature.query-results.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,44 @@
4040
"Examples Tables",
4141
"Examples Tables"
4242
],
43+
"findLocationBy" : [
44+
{
45+
"line" : 19,
46+
"column" : 7
47+
},
48+
{
49+
"line" : 20,
50+
"column" : 7
51+
},
52+
{
53+
"line" : 25,
54+
"column" : 7
55+
},
56+
{
57+
"line" : 26,
58+
"column" : 7
59+
},
60+
{
61+
"line" : 31,
62+
"column" : 7
63+
},
64+
{
65+
"line" : 32,
66+
"column" : 7
67+
},
68+
{
69+
"line" : 41,
70+
"column" : 7
71+
},
72+
{
73+
"line" : 42,
74+
"column" : 7
75+
},
76+
{
77+
"line" : 43,
78+
"column" : 7
79+
}
80+
],
4381
"findMeta" : "fake-cucumber",
4482
"findMostSevereTestStepResultBy" : [
4583
"PASSED",

testdata/hooks.feature.query-results.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@
5959
"6",
6060
"4"
6161
],
62+
"findLocationBy" : [
63+
{
64+
"line" : 6,
65+
"column" : 3
66+
},
67+
{
68+
"line" : 9,
69+
"column" : 3
70+
},
71+
{
72+
"line" : 12,
73+
"column" : 3
74+
},
75+
{
76+
"line" : 16,
77+
"column" : 3
78+
},
79+
{
80+
"line" : 20,
81+
"column" : 3
82+
}
83+
],
6284
"findMeta" : "fake-cucumber",
6385
"findMostSevereTestStepResultBy" : [
6486
"PASSED",

testdata/minimal.feature.query-results.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"findFeatureBy" : [
2525
"minimal"
2626
],
27+
"findLocationBy" : [
28+
{
29+
"line" : 9,
30+
"column" : 3
31+
}
32+
],
2733
"findMeta" : "fake-cucumber",
2834
"findMostSevereTestStepResultBy" : [
2935
"PASSED"

testdata/rules.feature.query-results.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828
"Usage of a `Rule`",
2929
"Usage of a `Rule`"
3030
],
31+
"findLocationBy" : [
32+
{
33+
"line" : 9,
34+
"column" : 5
35+
},
36+
{
37+
"line" : 16,
38+
"column" : 5
39+
},
40+
{
41+
"line" : 25,
42+
"column" : 5
43+
}
44+
],
3145
"findMeta" : "fake-cucumber",
3246
"findMostSevereTestStepResultBy" : [
3347
"PASSED",

0 commit comments

Comments
 (0)