Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 1bb892e

Browse files
mhalbrittersdeleuze
authored andcommitted
Fix native test failures with Graal 22.1
- The failures occur because MockitoTestExecutionListener and ResetMocksTestExecutionListener tried to initialize Mockito, which isn't supported yet. - This change ignores both listeners when running in AOT mode Closes gh-1561
1 parent a094918 commit 1bb892e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

spring-aot/src/main/java/org/springframework/aot/factories/IgnoredFactoriesCodeContributor.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
package org.springframework.aot.factories;
1818

1919
import java.util.Arrays;
20-
import java.util.List;
20+
import java.util.HashSet;
21+
import java.util.Set;
2122
import java.util.function.Predicate;
2223

2324
import org.apache.commons.logging.Log;
@@ -52,12 +53,21 @@ class IgnoredFactoriesCodeContributor implements FactoriesCodeContributor {
5253
"org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizerFactory",
5354
"org.springframework.boot.test.context.ImportsContextCustomizerFactory");
5455

56+
private static final Predicate<SpringFactory> IGNORED_TEST_EXECUTION_LISTENERS = factoryEntry(
57+
"org.springframework.test.context.TestExecutionListener",
58+
"org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener",
59+
"org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener"
60+
);
61+
5562
private final Log logger = LogFactory.getLog(IgnoredFactoriesCodeContributor.class);
5663

5764
@Override
5865
public boolean canContribute(SpringFactory factory) {
59-
return IGNORED_FACTORY_PACKAGES.or(IGNORED_FACTORY_TYPES)
60-
.or(CONTEXT_CUSTOMIZER_FACTORY).test(factory);
66+
return IGNORED_FACTORY_PACKAGES
67+
.or(IGNORED_FACTORY_TYPES)
68+
.or(CONTEXT_CUSTOMIZER_FACTORY)
69+
.or(IGNORED_TEST_EXECUTION_LISTENERS)
70+
.test(factory);
6171
}
6272

6373
@Override
@@ -67,7 +77,7 @@ public void contribute(SpringFactory factory, CodeGenerator code, BuildContext c
6777
}
6878

6979
private static Predicate<SpringFactory> factoryTypes(String... factoryTypes) {
70-
List<String> candidates = Arrays.asList(factoryTypes);
80+
Set<String> candidates = new HashSet<>(Arrays.asList(factoryTypes));
7181
return (springFactory) -> candidates.contains(springFactory.getFactoryType().getName());
7282
}
7383

@@ -83,7 +93,7 @@ private static Predicate<SpringFactory> factoriesInPackages(String... packageNam
8393
}
8494

8595
private static Predicate<SpringFactory> factoryEntry(String factoryType, String... factoryImplementations) {
86-
List<String> candidateImplementations = Arrays.asList(factoryImplementations);
96+
Set<String> candidateImplementations = new HashSet<>(Arrays.asList(factoryImplementations));
8797
return factoryTypes(factoryType).and((springFactory) ->
8898
candidateImplementations.contains(springFactory.getFactory().getName()));
8999
}

0 commit comments

Comments
 (0)