Skip to content

Commit becb779

Browse files
committed
Add test
1 parent 15176ed commit becb779

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
@@ -96,6 +96,52 @@
9696
"Attachments",
9797
"Attachments"
9898
],
99+
"findLocationBy" : [
100+
{
101+
"line" : 12,
102+
"column" : 3
103+
},
104+
{
105+
"line" : 18,
106+
"column" : 3
107+
},
108+
{
109+
"line" : 21,
110+
"column" : 3
111+
},
112+
{
113+
"line" : 24,
114+
"column" : 3
115+
},
116+
{
117+
"line" : 30,
118+
"column" : 3
119+
},
120+
{
121+
"line" : 33,
122+
"column" : 3
123+
},
124+
{
125+
"line" : 36,
126+
"column" : 3
127+
},
128+
{
129+
"line" : 44,
130+
"column" : 7
131+
},
132+
{
133+
"line" : 45,
134+
"column" : 7
135+
},
136+
{
137+
"line" : 47,
138+
"column" : 3
139+
},
140+
{
141+
"line" : 50,
142+
"column" : 3
143+
}
144+
],
99145
"findMeta" : "fake-cucumber",
100146
"findMostSevereTestStepResultBy" : [
101147
"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
@@ -36,6 +36,28 @@
3636
"0",
3737
"3"
3838
],
39+
"findLocationBy" : [
40+
{
41+
"line" : 6,
42+
"column" : 3
43+
},
44+
{
45+
"line" : 9,
46+
"column" : 3
47+
},
48+
{
49+
"line" : 12,
50+
"column" : 3
51+
},
52+
{
53+
"line" : 16,
54+
"column" : 3
55+
},
56+
{
57+
"line" : 20,
58+
"column" : 3
59+
}
60+
],
3961
"findMeta" : "fake-cucumber",
4062
"findMostSevereTestStepResultBy" : [
4163
"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)