Skip to content

Commit bbf8577

Browse files
authored
java: Use message comparators (#87)
1 parent ea88e59 commit bbf8577

File tree

3 files changed

+6
-80
lines changed

3 files changed

+6
-80
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.cucumber.query;
22

33
import io.cucumber.messages.Convertor;
4+
import io.cucumber.messages.TestStepResultStatusComparator;
45
import io.cucumber.messages.types.Attachment;
56
import io.cucumber.messages.types.Envelope;
67
import io.cucumber.messages.types.Examples;
@@ -35,7 +36,6 @@
3536
import java.util.Arrays;
3637
import java.util.Collection;
3738
import java.util.Collections;
38-
import java.util.Comparator;
3939
import java.util.EnumMap;
4040
import java.util.HashMap;
4141
import java.util.LinkedHashMap;
@@ -46,11 +46,9 @@
4646
import java.util.Objects;
4747
import java.util.function.BiFunction;
4848
import java.util.function.Supplier;
49-
import java.util.stream.Collectors;
5049

5150
import static java.util.Collections.emptyList;
5251
import static java.util.Comparator.comparing;
53-
import static java.util.Comparator.nullsFirst;
5452
import static java.util.Objects.requireNonNull;
5553
import static java.util.Optional.ofNullable;
5654
import static java.util.function.Function.identity;
@@ -72,9 +70,6 @@
7270
* @see <a href="https://github.com/cucumber/messages?tab=readme-ov-file#message-overview">Cucumber Messages - Message Overview</a>
7371
*/
7472
public final class Query {
75-
private static final Map<TestStepResultStatus, Long> ZEROES_BY_TEST_STEP_RESULT_STATUSES = Arrays.stream(TestStepResultStatus.values())
76-
.collect(Collectors.toMap(identity(), (s) -> 0L));
77-
private final Comparator<TestStepResult> testStepResultComparator = nullsFirst(comparing(o -> o.getStatus().ordinal()));
7873
private final Map<String, TestCaseStarted> testCaseStartedById = new LinkedHashMap<>();
7974
private final Map<String, TestCaseFinished> testCaseFinishedByTestCaseStartedId = new LinkedHashMap<>();
8075
private final Map<String, List<TestStepFinished>> testStepsFinishedByTestCaseStartedId = new LinkedHashMap<>();
@@ -94,7 +89,10 @@ public final class Query {
9489
private TestRunFinished testRunFinished;
9590

9691
public Map<TestStepResultStatus, Long> countMostSevereTestStepResultStatus() {
97-
EnumMap<TestStepResultStatus, Long> results = new EnumMap<>(ZEROES_BY_TEST_STEP_RESULT_STATUSES);
92+
EnumMap<TestStepResultStatus, Long> results = new EnumMap<>(TestStepResultStatus.class);
93+
for (TestStepResultStatus value : TestStepResultStatus.values()) {
94+
results.put(value, 0L);
95+
}
9896
results.putAll(findAllTestCaseStarted().stream()
9997
.map(this::findMostSevereTestStepResultBy)
10098
.filter(Optional::isPresent)
@@ -205,7 +203,7 @@ public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseStarted t
205203
return findTestStepsFinishedBy(testCaseStarted)
206204
.stream()
207205
.map(TestStepFinished::getTestStepResult)
208-
.max(testStepResultComparator);
206+
.max(comparing(TestStepResult::getStatus, new TestStepResultStatusComparator()));
209207
}
210208

211209
public Optional<TestStepResult> findMostSevereTestStepResultBy(TestCaseFinished testCaseFinished) {

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

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

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

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

0 commit comments

Comments
 (0)