11package io .cucumber .query ;
22
33import io .cucumber .messages .Convertor ;
4+ import io .cucumber .messages .TestStepResultStatusComparator ;
45import io .cucumber .messages .types .Attachment ;
56import io .cucumber .messages .types .Envelope ;
67import io .cucumber .messages .types .Examples ;
3536import java .util .Arrays ;
3637import java .util .Collection ;
3738import java .util .Collections ;
38- import java .util .Comparator ;
3939import java .util .EnumMap ;
4040import java .util .HashMap ;
4141import java .util .LinkedHashMap ;
4646import java .util .Objects ;
4747import java .util .function .BiFunction ;
4848import java .util .function .Supplier ;
49- import java .util .stream .Collectors ;
5049
5150import static java .util .Collections .emptyList ;
5251import static java .util .Comparator .comparing ;
53- import static java .util .Comparator .nullsFirst ;
5452import static java .util .Objects .requireNonNull ;
5553import static java .util .Optional .ofNullable ;
5654import static java .util .function .Function .identity ;
7270 * @see <a href="https://github.com/cucumber/messages?tab=readme-ov-file#message-overview">Cucumber Messages - Message Overview</a>
7371 */
7472public 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 ) {
0 commit comments