Skip to content

Commit 5669ea6

Browse files
committed
Consider properties on outer class in nested sliced tests
Prior to this commit, properties configured using the properties attribute of a `@…Test` sliced test annotation would not be considered when processed a `@Nested` test class. This would lead to the nested class not reusing its outer class's application context due to the two having different property configuration. Fixes gh-33317
1 parent 17a4d30 commit 5669ea6

File tree

36 files changed

+407
-123
lines changed

36 files changed

+407
-123
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/cassandra/DataCassandraTestContextBootstrapper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.cassandra;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -31,10 +30,9 @@ class DataCassandraTestContextBootstrapper extends SpringBootTestContextBootstra
3130

3231
@Override
3332
protected String[] getProperties(Class<?> testClass) {
34-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
35-
.get(DataCassandraTest.class)
36-
.getValue("properties", String[].class)
37-
.orElse(null);
33+
DataCassandraTest dataCassandraTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34+
DataCassandraTest.class);
35+
return (dataCassandraTest != null) ? dataCassandraTest.properties() : null;
3836
}
3937

4038
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/couchbase/DataCouchbaseTestContextBootstrapper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.couchbase;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -31,10 +30,9 @@ class DataCouchbaseTestContextBootstrapper extends SpringBootTestContextBootstra
3130

3231
@Override
3332
protected String[] getProperties(Class<?> testClass) {
34-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
35-
.get(DataCouchbaseTest.class)
36-
.getValue("properties", String[].class)
37-
.orElse(null);
33+
DataCouchbaseTest dataCouchbaseTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34+
DataCouchbaseTest.class);
35+
return (dataCouchbaseTest != null) ? dataCouchbaseTest.properties() : null;
3836
}
3937

4038
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/elasticsearch/DataElasticsearchTestContextBootstrapper.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.elasticsearch;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -31,10 +30,9 @@ class DataElasticsearchTestContextBootstrapper extends SpringBootTestContextBoot
3130

3231
@Override
3332
protected String[] getProperties(Class<?> testClass) {
34-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
35-
.get(DataElasticsearchTest.class)
36-
.getValue("properties", String[].class)
37-
.orElse(null);
33+
DataElasticsearchTest dataElasticsearchTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34+
DataElasticsearchTest.class);
35+
return (dataElasticsearchTest != null) ? dataElasticsearchTest.properties() : null;
3836
}
3937

4038
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.jdbc;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataJdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataJdbcTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataJdbcTest dataJdbcTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataJdbcTest.class);
33+
return (dataJdbcTest != null) ? dataJdbcTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.ldap;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataLdapTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataLdapTest dataLdapTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataLdapTest.class);
33+
return (dataLdapTest != null) ? dataLdapTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.mongo;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataMongoTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataMongoTest dataMongoTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataMongoTest.class);
33+
return (dataMongoTest != null) ? dataMongoTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.neo4j;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataNeo4jTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataNeo4jTest dataNeo4jTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataNeo4jTest.class);
33+
return (dataNeo4jTest != null) ? dataNeo4jTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/r2dbc/DataR2dbcTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.r2dbc;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataR2dbcTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataR2dbcTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataR2dbcTest dataR2dbcTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataR2dbcTest.class);
33+
return (dataR2dbcTest != null) ? dataR2dbcTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.data.redis;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
21-
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2221
import org.springframework.test.context.TestContextBootstrapper;
2322

2423
/**
@@ -30,10 +29,8 @@ class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper
3029

3130
@Override
3231
protected String[] getProperties(Class<?> testClass) {
33-
return MergedAnnotations.from(testClass, SearchStrategy.INHERITED_ANNOTATIONS)
34-
.get(DataRedisTest.class)
35-
.getValue("properties", String[].class)
36-
.orElse(null);
32+
DataRedisTest dataRedisTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataRedisTest.class);
33+
return (dataRedisTest != null) ? dataRedisTest.properties() : null;
3734
}
3835

3936
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/GraphQlTestContextBootstrapper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.boot.test.autoconfigure.graphql;
1818

1919
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.core.annotation.MergedAnnotations;
20+
import org.springframework.test.context.TestContextAnnotationUtils;
2121
import org.springframework.test.context.TestContextBootstrapper;
2222

2323
/**
@@ -29,10 +29,8 @@ class GraphQlTestContextBootstrapper extends SpringBootTestContextBootstrapper {
2929

3030
@Override
3131
protected String[] getProperties(Class<?> testClass) {
32-
return MergedAnnotations.from(testClass, MergedAnnotations.SearchStrategy.INHERITED_ANNOTATIONS)
33-
.get(GraphQlTest.class)
34-
.getValue("properties", String[].class)
35-
.orElse(null);
32+
GraphQlTest graphQlTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, GraphQlTest.class);
33+
return (graphQlTest != null) ? graphQlTest.properties() : null;
3634
}
3735

3836
}

0 commit comments

Comments
 (0)