diff --git a/CHANGELOG.md b/CHANGELOG.md index 14f33e0b..56e89c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed +- [Java] increase dependency messages to at least v28.1 ([#87](https://github.com/cucumber/query/pull/87)) + ## [13.6.0] - 2025-08-11 ### Changed diff --git a/java/pom.xml b/java/pom.xml index cfef396a..f34d1a04 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -51,7 +51,7 @@ io.cucumber messages - [24.0.0,29.0.0) + [28.1.0,29.0.0) diff --git a/java/src/main/java/io/cucumber/query/Query.java b/java/src/main/java/io/cucumber/query/Query.java index a0f4ccb9..aff9957c 100644 --- a/java/src/main/java/io/cucumber/query/Query.java +++ b/java/src/main/java/io/cucumber/query/Query.java @@ -1,6 +1,7 @@ package io.cucumber.query; import io.cucumber.messages.Convertor; +import io.cucumber.messages.TestStepResultStatusComparator; import io.cucumber.messages.types.Attachment; import io.cucumber.messages.types.Envelope; import io.cucumber.messages.types.Examples; @@ -31,9 +32,7 @@ import java.time.Duration; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; import java.util.LinkedHashMap; @@ -44,11 +43,9 @@ import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Supplier; -import java.util.stream.Collectors; import static java.util.Collections.emptyList; import static java.util.Comparator.comparing; -import static java.util.Comparator.nullsFirst; import static java.util.Objects.requireNonNull; import static java.util.Optional.ofNullable; import static java.util.function.Function.identity; @@ -70,9 +67,6 @@ * @see Cucumber Messages - Message Overview */ public final class Query { - private static final Map ZEROES_BY_TEST_STEP_RESULT_STATUSES = Arrays.stream(TestStepResultStatus.values()) - .collect(Collectors.toMap(identity(), (s) -> 0L)); - private final Comparator testStepResultComparator = nullsFirst(comparing(o -> o.getStatus().ordinal())); private final Map testCaseStartedById = new LinkedHashMap<>(); private final Map testCaseFinishedByTestCaseStartedId = new HashMap<>(); private final Map> testStepsFinishedByTestCaseStartedId = new HashMap<>(); @@ -91,7 +85,10 @@ public final class Query { private TestRunFinished testRunFinished; public Map countMostSevereTestStepResultStatus() { - EnumMap results = new EnumMap<>(ZEROES_BY_TEST_STEP_RESULT_STATUSES); + EnumMap results = new EnumMap<>(TestStepResultStatus.class); + for (TestStepResultStatus value : TestStepResultStatus.values()) { + results.put(value, 0L); + } results.putAll(findAllTestCaseStarted().stream() .map(this::findMostSevereTestStepResultBy) .filter(Optional::isPresent) @@ -172,7 +169,7 @@ public Optional findMostSevereTestStepResultBy(TestCaseStarted t return findTestStepsFinishedBy(testCaseStarted) .stream() .map(TestStepFinished::getTestStepResult) - .max(testStepResultComparator); + .max(comparing(TestStepResult::getStatus, new TestStepResultStatusComparator())); } public String findNameOf(GherkinDocument element, NamingStrategy namingStrategy) { diff --git a/java/src/main/java/io/cucumber/query/TimestampComparator.java b/java/src/main/java/io/cucumber/query/TimestampComparator.java deleted file mode 100644 index 29ed2794..00000000 --- a/java/src/main/java/io/cucumber/query/TimestampComparator.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.cucumber.query; - -import io.cucumber.messages.types.Timestamp; - -import java.util.Comparator; - -class TimestampComparator implements Comparator { - @Override - public int compare(Timestamp a, Timestamp b) { - long sa = a.getSeconds(); - long sb = b.getSeconds(); - - if (sa < sb) { - return -1; - } else if (sb < sa) { - return 1; - } - - long na = a.getNanos(); - long nb = b.getNanos(); - - if (na < nb) { - return -1; - } else if (nb < na) { - return 1; - } - - return 0; - } -} diff --git a/java/src/test/java/io/cucumber/query/TimestampComparatorTest.java b/java/src/test/java/io/cucumber/query/TimestampComparatorTest.java deleted file mode 100644 index d48e6e99..00000000 --- a/java/src/test/java/io/cucumber/query/TimestampComparatorTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.cucumber.query; - -import io.cucumber.messages.types.Timestamp; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class TimestampComparatorTest { - - private final TimestampComparator comparator = new TimestampComparator(); - - @Test - void identity(){ - Timestamp a = new Timestamp(1L, 1L); - Timestamp b = new Timestamp(1L, 1L); - - assertThat(comparator.compare(a, b)).isEqualTo(0); - assertThat(comparator.compare(b, a)).isEqualTo(0); - } - - @Test - void onSeconds(){ - Timestamp a = new Timestamp(1L, 1L); - Timestamp b = new Timestamp(2L, 2L); - assertThat(comparator.compare(a, b)).isEqualTo(-1); - assertThat(comparator.compare(b, a)).isEqualTo(1); - } - - @Test - void onNanoSeconds(){ - Timestamp a = new Timestamp(1L, 1L); - Timestamp b1 = new Timestamp(1L, 0L); - Timestamp b2 = new Timestamp(1L, 2L); - - assertThat(comparator.compare(a, b1)).isEqualTo(1); - assertThat(comparator.compare(b1, a)).isEqualTo(-1); - - assertThat(comparator.compare(a, b2)).isEqualTo(-1); - assertThat(comparator.compare(b2, a)).isEqualTo(1); - - } -}