Skip to content

Conversation

@sbrannen
Copy link
Member

@sbrannen sbrannen commented Aug 22, 2025

Prior to this commit, LauncherDiscoveryResult.retainEngines() stored the pruned LinkedHashMap content in a HashMap, which sometimes resulted in different iteration order for pruned test engines.

To address that, this commit replaces the use of Collectors.toMap(Function<? super T, ? extends K>, Function<? super T, ? extends U>) -- which creates a HashMap -- with the use of Collectors.toMap(Function<? super T, ? extends K>, Function<? super T, ? extends U>, BinaryOperator<U>, Supplier<M>) -- which allows us to specify that the pruned test engines should be stored in a LinkedHashMap to retain the original iteration order.

Fixes #4862

Prior to this commit, LauncherDiscoveryResult.retainEngines() stored the
pruned LinkedHashMap content in a HashMap, which sometimes resulted in
different iteration order for pruned test engines.

To address that, this commit replaces the use of
Collectors.toMap(Function<? super T, ? extends K>, Function<? super T, ? extends U>)
-- which creates a HashMap -- with the use of
Collectors.toMap(Function<? super T, ? extends K>, Function<? super T, ? extends U>, BinaryOperator<U>, Supplier<M>)
-- which allows us to specify that the pruned test engines should be
stored in a LinkedHashMap to retain the original iteration order.

Fixes junit-team#4862
@sbrannen

This comment was marked as outdated.

@sbrannen sbrannen changed the title Retain TestEngine order after pruning Retain original TestEngine order after pruning Aug 22, 2025
sormuras

This comment was marked as outdated.

@sbrannen sbrannen merged commit a400fc6 into junit-team:main Aug 22, 2025
14 checks passed
marcphilipp pushed a commit that referenced this pull request Sep 22, 2025
Prior to this commit, LauncherDiscoveryResult.retainEngines() stored the
retained LinkedHashMap content in a HashMap, which sometimes resulted in
different iteration order if test engines were pruned.

To address that, this commit replaces the use of the Stream API and
Collectors.toMap() (which creates a HashMap) -- with the use of a
LinkedHashMap combined with entrySet().removeIf() which allows us to
ensure that the retained test engines are stored in a LinkedHashMap
that maintains the original iteration order.

Fixes #4862
Closes #4864

(cherry picked from commit a400fc6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LauncherDiscoveryResult loses original TestEngine registration order if engines are pruned

3 participants