Skip to content

Commit

Permalink
Fix native test failures with Graal 22.1
Browse files Browse the repository at this point in the history
- 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 spring-atticgh-1561
  • Loading branch information
mhalbritter committed Mar 31, 2022
1 parent 1242068 commit fc45093
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package org.springframework.aot.factories;

import java.util.Arrays;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;

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

private static final Predicate<SpringFactory> TEST_EXECUTION_LISTENERS = factoryEntry(
"org.springframework.test.context.TestExecutionListener",
"org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener",
"org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener"
);

private final Log logger = LogFactory.getLog(IgnoredFactoriesCodeContributor.class);

@Override
public boolean canContribute(SpringFactory factory) {
return IGNORED_FACTORY_PACKAGES.or(IGNORED_FACTORY_TYPES)
.or(CONTEXT_CUSTOMIZER_FACTORY).test(factory);
return IGNORED_FACTORY_PACKAGES
.or(IGNORED_FACTORY_TYPES)
.or(CONTEXT_CUSTOMIZER_FACTORY)
.or(TEST_EXECUTION_LISTENERS)
.test(factory);
}

@Override
Expand All @@ -67,7 +77,7 @@ public void contribute(SpringFactory factory, CodeGenerator code, BuildContext c
}

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

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

private static Predicate<SpringFactory> factoryEntry(String factoryType, String... factoryImplementations) {
List<String> candidateImplementations = Arrays.asList(factoryImplementations);
Set<String> candidateImplementations = new HashSet<>(Arrays.asList(factoryImplementations));
return factoryTypes(factoryType).and((springFactory) ->
candidateImplementations.contains(springFactory.getFactory().getName()));
}
Expand Down

0 comments on commit fc45093

Please sign in to comment.