Skip to content

Commit db0287c

Browse files
committed
Merge pull request #28563 from ledoyen
* pr/28563: Polish 'Ignore JUnit annotations when caching test contexts' Ignore JUnit annotations when caching test contexts Closes gh-28563
2 parents e802d6b + 8a14e1e commit db0287c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -222,6 +222,7 @@ static class ContextCustomizerKey {
222222
filters.add(new JavaLangAnnotationFilter());
223223
filters.add(new KotlinAnnotationFilter());
224224
filters.add(new SpockAnnotationFilter());
225+
filters.add(new JunitAnnotationFilter());
225226
ANNOTATION_FILTERS = Collections.unmodifiableSet(filters);
226227
}
227228

@@ -384,4 +385,16 @@ public boolean isIgnored(Annotation annotation) {
384385

385386
}
386387

388+
/**
389+
* {@link AnnotationFilter} for JUnit annotations.
390+
*/
391+
private static final class JunitAnnotationFilter implements AnnotationFilter {
392+
393+
@Override
394+
public boolean isIgnored(Annotation annotation) {
395+
return annotation.annotationType().getName().startsWith("org.junit.");
396+
}
397+
398+
}
399+
387400
}

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/ImportsContextCustomizerTests.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222
import java.util.Set;
2323

2424
import kotlin.Metadata;
25+
import org.junit.jupiter.api.Nested;
26+
import org.junit.jupiter.api.Tag;
2527
import org.junit.jupiter.api.Test;
2628
import org.spockframework.runtime.model.SpecMetadata;
2729
import spock.lang.Issue;
@@ -72,6 +74,12 @@ void customizersForTestClassesWithDifferentSpockLangAnnotationsAreEqual() {
7274
.isEqualTo(new ImportsContextCustomizer(SecondSpockLangAnnotatedTestClass.class));
7375
}
7476

77+
@Test
78+
void customizersForTestClassesWithDifferentJunitAnnotationsAreEqual() {
79+
assertThat(new ImportsContextCustomizer(FirstJunitAnnotatedTestClass.class))
80+
.isEqualTo(new ImportsContextCustomizer(SecondJunitAnnotatedTestClass.class));
81+
}
82+
7583
@Import(TestImportSelector.class)
7684
@Indicator1
7785
static class FirstImportSelectorAnnotatedClass {
@@ -126,6 +134,18 @@ static class SecondSpockLangAnnotatedTestClass {
126134

127135
}
128136

137+
@Nested
138+
@Import(TestImportSelector.class)
139+
static class FirstJunitAnnotatedTestClass {
140+
141+
}
142+
143+
@Tag("test")
144+
@Import(TestImportSelector.class)
145+
static class SecondJunitAnnotatedTestClass {
146+
147+
}
148+
129149
@Retention(RetentionPolicy.RUNTIME)
130150
@interface Indicator1 {
131151

0 commit comments

Comments
 (0)