Skip to content

Commit a42ba82

Browse files
quaffwilkinsona
authored andcommitted
Introduce TestSliceTestContextBootstrapper for test slices
Signed-off-by: Yanming Zhou <[email protected]> See gh-44354
1 parent 8bb5c27 commit a42ba82

20 files changed

+98
-177
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.cassandra;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
@@ -26,13 +25,6 @@
2625
*
2726
* @author Artsiom Yudovin
2827
*/
29-
class DataCassandraTestContextBootstrapper extends SpringBootTestContextBootstrapper {
30-
31-
@Override
32-
protected String[] getProperties(Class<?> testClass) {
33-
DataCassandraTest dataCassandraTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34-
DataCassandraTest.class);
35-
return (dataCassandraTest != null) ? dataCassandraTest.properties() : null;
36-
}
28+
class DataCassandraTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataCassandraTest> {
3729

3830
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.couchbase;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
@@ -26,13 +25,6 @@
2625
*
2726
* @author Eddú Meléndez
2827
*/
29-
class DataCouchbaseTestContextBootstrapper extends SpringBootTestContextBootstrapper {
30-
31-
@Override
32-
protected String[] getProperties(Class<?> testClass) {
33-
DataCouchbaseTest dataCouchbaseTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34-
DataCouchbaseTest.class);
35-
return (dataCouchbaseTest != null) ? dataCouchbaseTest.properties() : null;
36-
}
28+
class DataCouchbaseTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataCouchbaseTest> {
3729

3830
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.elasticsearch;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
@@ -26,13 +25,6 @@
2625
*
2726
* @author Eddú Meléndez
2827
*/
29-
class DataElasticsearchTestContextBootstrapper extends SpringBootTestContextBootstrapper {
30-
31-
@Override
32-
protected String[] getProperties(Class<?> testClass) {
33-
DataElasticsearchTest dataElasticsearchTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
34-
DataElasticsearchTest.class);
35-
return (dataElasticsearchTest != null) ? dataElasticsearchTest.properties() : null;
36-
}
28+
class DataElasticsearchTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataElasticsearchTest> {
3729

3830
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.jdbc;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataJdbcTest @DataJdbcTest} support.
2524
*
2625
* @author Andy Wilkinson
2726
*/
28-
class DataJdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataJdbcTest dataJdbcTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataJdbcTest.class);
33-
return (dataJdbcTest != null) ? dataJdbcTest.properties() : null;
34-
}
27+
class DataJdbcTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataJdbcTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.ldap;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataLdapTest @DataLdapTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataLdapTest dataLdapTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataLdapTest.class);
33-
return (dataLdapTest != null) ? dataLdapTest.properties() : null;
34-
}
27+
class DataLdapTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataLdapTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.mongo;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataMongoTest @DataMongoTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataMongoTest dataMongoTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataMongoTest.class);
33-
return (dataMongoTest != null) ? dataMongoTest.properties() : null;
34-
}
27+
class DataMongoTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataMongoTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.neo4j;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataNeo4jTest @DataNeo4jTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataNeo4jTest dataNeo4jTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataNeo4jTest.class);
33-
return (dataNeo4jTest != null) ? dataNeo4jTest.properties() : null;
34-
}
27+
class DataNeo4jTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataNeo4jTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.r2dbc;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataR2dbcTest @DataR2dbcTest} support.
2524
*
2625
* @author Mark Paluch
2726
*/
28-
class DataR2dbcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataR2dbcTest dataR2dbcTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataR2dbcTest.class);
33-
return (dataR2dbcTest != null) ? dataR2dbcTest.properties() : null;
34-
}
27+
class DataR2dbcTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataR2dbcTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.data.redis;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataRedisTest @DataRedisTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataRedisTest dataRedisTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataRedisTest.class);
33-
return (dataRedisTest != null) ? dataRedisTest.properties() : null;
34-
}
27+
class DataRedisTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataRedisTest> {
3528

3629
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.graphql;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link GraphQlTest @GraphQlTest}.
2524
*
2625
* @author Brian Clozel
2726
*/
28-
class GraphQlTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
GraphQlTest graphQlTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, GraphQlTest.class);
33-
return (graphQlTest != null) ? graphQlTest.properties() : null;
34-
}
27+
class GraphQlTestContextBootstrapper extends TestSliceTestContextBootstrapper<GraphQlTest> {
3528

3629
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@
1616

1717
package org.springframework.boot.test.autoconfigure.jdbc;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link JdbcTest @JdbcTest} support.
2524
*
2625
* @author Artsiom Yudovin
26+
* @author Yanming Zhou
2727
*/
28-
class JdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
JdbcTest jdbcTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, JdbcTest.class);
33-
return (jdbcTest != null) ? jdbcTest.properties() : null;
34-
}
28+
class JdbcTestContextBootstrapper extends TestSliceTestContextBootstrapper<JdbcTest> {
3529

3630
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.jooq;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link JooqTest @JooqTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class JooqTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
JooqTest jooqTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, JooqTest.class);
33-
return (jooqTest != null) ? jooqTest.properties() : null;
34-
}
27+
class JooqTestContextBootstrapper extends TestSliceTestContextBootstrapper<JooqTest> {
3528

3629
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.json;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link JsonTest @JsonTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class JsonTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
JsonTest jsonTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, JsonTest.class);
33-
return (jsonTest != null) ? jsonTest.properties() : null;
34-
}
27+
class JsonTestContextBootstrapper extends TestSliceTestContextBootstrapper<JsonTest> {
3528

3629
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.orm.jpa;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link DataJpaTest @DataJpaTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class DataJpaTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
DataJpaTest dataJpaTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, DataJpaTest.class);
33-
return (dataJpaTest != null) ? dataJpaTest.properties() : null;
34-
}
27+
class DataJpaTestContextBootstrapper extends TestSliceTestContextBootstrapper<DataJpaTest> {
3528

3629
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@
1616

1717
package org.springframework.boot.test.autoconfigure.web.client;
1818

19-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20-
import org.springframework.test.context.TestContextAnnotationUtils;
19+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2120
import org.springframework.test.context.TestContextBootstrapper;
2221

2322
/**
2423
* {@link TestContextBootstrapper} for {@link RestClientTest @RestClientTest} support.
2524
*
2625
* @author Artsiom Yudovin
2726
*/
28-
class RestClientTestContextBootstrapper extends SpringBootTestContextBootstrapper {
29-
30-
@Override
31-
protected String[] getProperties(Class<?> testClass) {
32-
RestClientTest restClientTest = TestContextAnnotationUtils.findMergedAnnotation(testClass,
33-
RestClientTest.class);
34-
return (restClientTest != null) ? restClientTest.properties() : null;
35-
}
27+
class RestClientTestContextBootstrapper extends TestSliceTestContextBootstrapper<RestClientTest> {
3628

3729
}

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
package org.springframework.boot.test.autoconfigure.web.reactive;
1818

1919
import org.springframework.boot.test.context.ReactiveWebMergedContextConfiguration;
20-
import org.springframework.boot.test.context.SpringBootTestContextBootstrapper;
20+
import org.springframework.boot.test.context.TestSliceTestContextBootstrapper;
2121
import org.springframework.test.context.MergedContextConfiguration;
22-
import org.springframework.test.context.TestContextAnnotationUtils;
2322
import org.springframework.test.context.TestContextBootstrapper;
2423

2524
/**
@@ -28,17 +27,11 @@
2827
* @author Stephane Nicoll
2928
* @author Artsiom Yudovin
3029
*/
31-
class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper {
30+
class WebFluxTestContextBootstrapper extends TestSliceTestContextBootstrapper<WebFluxTest> {
3231

3332
@Override
3433
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
3534
return new ReactiveWebMergedContextConfiguration(super.processMergedContextConfiguration(mergedConfig));
3635
}
3736

38-
@Override
39-
protected String[] getProperties(Class<?> testClass) {
40-
WebFluxTest webFluxTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, WebFluxTest.class);
41-
return (webFluxTest != null) ? webFluxTest.properties() : null;
42-
}
43-
4437
}

0 commit comments

Comments
 (0)