diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java index fa2a4c82f7..f51692cb34 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java @@ -29,9 +29,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; import org.springframework.core.convert.converter.Converter; import org.springframework.data.cassandra.core.CassandraTemplate; import org.springframework.data.cassandra.core.convert.CassandraCustomConversions; @@ -63,7 +61,7 @@ class CassandraDataAutoConfigurationTests { @Test void templateExists() { - load(TestExcludeConfiguration.class); + load(TestConfiguration.class); assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1); } @@ -117,13 +115,6 @@ class CassandraDataAutoConfigurationTests { this.context = ctx; } - @Configuration(proxyBeanMethods = false) - @ComponentScan( - excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE)) - static class TestExcludeConfiguration { - - } - @Configuration(proxyBeanMethods = false) static class TestConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java index 15a0c6c62a..0daffd5879 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java @@ -33,11 +33,7 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; -import org.springframework.data.cassandra.ReactiveSession; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories; import org.springframework.test.util.ReflectionTestUtils; @@ -71,16 +67,15 @@ class CassandraReactiveRepositoriesAutoConfigurationTests { @Test void testNoRepositoryConfiguration() { - this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class) - .run((context) -> { - assertThat(context).hasSingleBean(Cluster.class); - assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); - }); + this.contextRunner.withUserConfiguration(TestConfiguration.class, EmptyConfiguration.class).run((context) -> { + assertThat(context).hasSingleBean(Cluster.class); + assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); + }); } @Test void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { - this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class) + this.contextRunner.withUserConfiguration(TestConfiguration.class, CustomizedConfiguration.class) .run((context) -> { assertThat(context).hasSingleBean(ReactiveCityCassandraRepository.class); assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); @@ -131,10 +126,4 @@ class CassandraReactiveRepositoriesAutoConfigurationTests { } - @Configuration(proxyBeanMethods = false) - @ComponentScan(excludeFilters = @Filter(classes = { ReactiveSession.class }, type = FilterType.ASSIGNABLE_TYPE)) - static class TestExcludeConfiguration { - - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java index 022b23f3e2..9fd5088639 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java @@ -33,9 +33,8 @@ import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.Import; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; import org.springframework.test.util.ReflectionTestUtils; @@ -58,7 +57,7 @@ class CassandraRepositoriesAutoConfigurationTests { @Test void testDefaultRepositoryConfiguration() { - this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { + this.contextRunner.withUserConfiguration(DefaultConfiguration.class).run((context) -> { assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(Cluster.class); assertThat(getInitialEntitySet(context)).hasSize(1); @@ -67,32 +66,30 @@ class CassandraRepositoriesAutoConfigurationTests { @Test void testNoRepositoryConfiguration() { - this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, EmptyConfiguration.class) - .run((context) -> { - assertThat(context).hasSingleBean(Cluster.class); - assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); - }); + this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> { + assertThat(context).hasSingleBean(Cluster.class); + assertThat(getInitialEntitySet(context)).isEmpty(); + }); } @Test void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { - this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class, CustomizedConfiguration.class) - .run((context) -> { - assertThat(context).hasSingleBean(CityCassandraRepository.class); - assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); - }); + this.contextRunner.withUserConfiguration(CustomizedConfiguration.class).run((context) -> { + assertThat(context).hasSingleBean(CityCassandraRepository.class); + assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class); + }); } @Test void enablingReactiveRepositoriesDisablesImperativeRepositories() { - this.contextRunner.withUserConfiguration(TestConfiguration.class) + this.contextRunner.withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.cassandra.repositories.type=reactive") .run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class)); } @Test void enablingNoRepositoriesDisablesImperativeRepositories() { - this.contextRunner.withUserConfiguration(TestConfiguration.class) + this.contextRunner.withUserConfiguration(DefaultConfiguration.class) .withPropertyValues("spring.data.cassandra.repositories.type=none") .run((context) -> assertThat(context).doesNotHaveBean(CityCassandraRepository.class)); } @@ -104,7 +101,6 @@ class CassandraRepositoriesAutoConfigurationTests { } @Configuration(proxyBeanMethods = false) - @TestAutoConfigurationPackage(City.class) static class TestConfiguration { @Bean @@ -116,21 +112,23 @@ class CassandraRepositoriesAutoConfigurationTests { @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(EmptyDataPackage.class) + @Import(TestConfiguration.class) static class EmptyConfiguration { } @Configuration(proxyBeanMethods = false) - @TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class) - @EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class) - static class CustomizedConfiguration { + @TestAutoConfigurationPackage(City.class) + @Import(TestConfiguration.class) + static class DefaultConfiguration { } @Configuration(proxyBeanMethods = false) - @ComponentScan( - excludeFilters = @ComponentScan.Filter(classes = { Session.class }, type = FilterType.ASSIGNABLE_TYPE)) - static class TestExcludeConfiguration { + @TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class) + @EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class) + @Import(TestConfiguration.class) + static class CustomizedConfiguration { }