From 23876d8a325fc15e254b85dfb61007ae0f7d078f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Ledoyen?= Date: Mon, 8 Nov 2021 19:00:54 +0100 Subject: [PATCH] Ignore JUnit annotations when caching test contexts Update `ImportsContextCustomizer` to ignore JUnit annotations. See gh-28563 --- .../boot/test/context/ImportsContextCustomizer.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java index 3d33b764ce5..e1e013d8c60 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java @@ -222,6 +222,7 @@ class ImportsContextCustomizer implements ContextCustomizer { filters.add(new JavaLangAnnotationFilter()); filters.add(new KotlinAnnotationFilter()); filters.add(new SpockAnnotationFilter()); + filters.add(new JunitAnnotationFilter()); ANNOTATION_FILTERS = Collections.unmodifiableSet(filters); } @@ -384,4 +385,15 @@ class ImportsContextCustomizer implements ContextCustomizer { } + /** + * {@link AnnotationFilter} for Spock annotations. + */ + private static final class JunitAnnotationFilter implements AnnotationFilter { + + @Override + public boolean isIgnored(Annotation annotation) { + return annotation.annotationType().getName().startsWith("org.junit."); + } + + } }