Skip to content

Commit 3c7bf67

Browse files
committed
Update dependency io.cucumber:query to v13.3
1 parent fc814dc commit 3c7bf67

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

java/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>io.cucumber</groupId>
6666
<artifactId>query</artifactId>
67-
<version>[13.0.2,14.0.0)</version>
67+
<version>[13.3.0,14.0.0)</version>
6868
</dependency>
6969

7070
<dependency>

java/src/main/java/io/cucumber/testngxmlformatter/XmlReportData.java

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import io.cucumber.messages.types.TestStepFinished;
1313
import io.cucumber.messages.types.TestStepResult;
1414
import io.cucumber.messages.types.TestStepResultStatus;
15+
import io.cucumber.query.Lineage;
1516
import io.cucumber.query.NamingStrategy;
1617
import io.cucumber.query.Query;
1718

1819
import java.time.Duration;
1920
import java.time.Instant;
2021
import java.time.format.DateTimeFormatter;
2122
import java.util.AbstractMap.SimpleEntry;
23+
import java.util.LinkedHashMap;
2224
import java.util.List;
2325
import java.util.Locale;
2426
import java.util.Map;
@@ -27,12 +29,20 @@
2729
import java.util.Set;
2830

2931
import static io.cucumber.messages.types.TestStepResultStatus.PASSED;
32+
import static java.util.Comparator.comparing;
33+
import static java.util.Comparator.naturalOrder;
34+
import static java.util.Comparator.nullsFirst;
35+
import static java.util.stream.Collectors.collectingAndThen;
36+
import static java.util.stream.Collectors.groupingBy;
3037
import static java.util.stream.Collectors.toList;
3138

3239
class XmlReportData {
3340

41+
private static final io.cucumber.messages.types.Duration ZERO_DURATION =
42+
new io.cucumber.messages.types.Duration(0L, 0L);
43+
// By definition, but see https://github.com/cucumber/gherkin/issues/11
44+
private static final TestStepResult SCENARIO_WITH_NO_STEPS = new TestStepResult(ZERO_DURATION, null, PASSED, null);
3445
final Query query = new Query();
35-
3646
private final NamingStrategy namingStrategy;
3747

3848
XmlReportData(NamingStrategy namingStrategy) {
@@ -66,8 +76,9 @@ int getTestCaseCount() {
6676
String getPickleName(TestCaseStarted testCaseStarted) {
6777
Pickle pickle = query.findPickleBy(testCaseStarted)
6878
.orElseThrow(() -> new IllegalStateException("No pickle for " + testCaseStarted.getId()));
69-
70-
return query.findNameOf(pickle, namingStrategy);
79+
return query.findLineageBy(pickle)
80+
.map(lineage -> namingStrategy.reduce(lineage, pickle))
81+
.orElseGet(pickle::getName);
7182
}
7283

7384
List<Entry<String, String>> getStepsAndResult(TestCaseStarted testCaseStarted) {
@@ -107,14 +118,40 @@ private String renderTestStepText(TestStep testStep) {
107118
}
108119

109120
Set<Entry<Optional<Feature>, List<TestCaseStarted>>> getAllTestCaseStartedGroupedByFeature() {
110-
return query.findAllTestCaseStartedGroupedByFeature().entrySet();
121+
return query.findAllTestCaseStarted()
122+
.stream()
123+
.map(testCaseStarted -> {
124+
Optional<Lineage> astNodes = query.findLineageBy(testCaseStarted);
125+
return new SimpleEntry<>(astNodes, testCaseStarted);
126+
})
127+
// Sort entries by gherkin document URI for consistent ordering
128+
.sorted(comparing(
129+
entry -> entry.getKey()
130+
.flatMap(nodes -> nodes.document().getUri())
131+
.orElse(null),
132+
nullsFirst(naturalOrder())
133+
))
134+
.map(entry -> {
135+
// Unpack the now sorted entries
136+
Optional<Feature> feature = entry.getKey().flatMap(Lineage::feature);
137+
TestCaseStarted testcaseStarted = entry.getValue();
138+
return new SimpleEntry<>(feature, testcaseStarted);
139+
})
140+
// Group into a linked hashmap to preserve order
141+
.collect(groupingBy(
142+
SimpleEntry::getKey,
143+
LinkedHashMap::new,
144+
collectingAndThen(
145+
toList(),
146+
entries -> entries.stream()
147+
.map(SimpleEntry::getValue)
148+
.collect(toList())
149+
)
150+
)
151+
)
152+
.entrySet();
111153
}
112154

113-
private static final io.cucumber.messages.types.Duration ZERO_DURATION =
114-
new io.cucumber.messages.types.Duration(0L, 0L);
115-
// By definition, but see https://github.com/cucumber/gherkin/issues/11
116-
private static final TestStepResult SCENARIO_WITH_NO_STEPS = new TestStepResult(ZERO_DURATION, null, PASSED, null);
117-
118155
TestStepResult getTestCaseStatus(TestCaseStarted testCaseStarted) {
119156
return query.findMostSevereTestStepResultBy(testCaseStarted)
120157
.orElse(SCENARIO_WITH_NO_STEPS);

0 commit comments

Comments
 (0)