Commit 555dd3bc authored by Stephane Nicoll's avatar Stephane Nicoll

Merge pull request #16758 from izeye

* pr/16758:
  Polish "Add negative tests to ConfigurationPropertiesScanTests"
  Add negative tests to ConfigurationPropertiesScanTests
parents 75eb0ef9 c85c653e
......@@ -34,6 +34,7 @@ import static org.mockito.BDDMockito.willCallRealMethod;
* Integration tests for {@link ConfigurationPropertiesScan}.
*
* @author Madhura Bhave
* @author Johnny Lim
*/
public class ConfigurationPropertiesScanTests {
......@@ -52,7 +53,7 @@ public class ConfigurationPropertiesScanTests {
}
@Test
public void scanImportBeanRegistrarShouldBeEnvironmentAware() {
public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithRequiredProfile() {
this.context.getEnvironment().addActiveProfile("test");
load(TestConfiguration.class);
assertThat(this.context.containsBean(
......@@ -61,7 +62,15 @@ public class ConfigurationPropertiesScanTests {
}
@Test
public void scanImportBeanRegistrarShouldBeResourceLoaderAware() {
public void scanImportBeanRegistrarShouldBeEnvironmentAwareWithoutRequiredProfile() {
load(TestConfiguration.class);
assertThat(this.context.containsBean(
"profile-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyProfileProperties"))
.isFalse();
}
@Test
public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithRequiredResource() {
DefaultResourceLoader resourceLoader = Mockito.mock(DefaultResourceLoader.class);
this.context.setResourceLoader(resourceLoader);
willCallRealMethod().given(resourceLoader).getClassLoader();
......@@ -73,6 +82,14 @@ public class ConfigurationPropertiesScanTests {
.isTrue();
}
@Test
public void scanImportBeanRegistrarShouldBeResourceLoaderAwareWithoutRequiredResource() {
load(TestConfiguration.class);
assertThat(this.context.containsBean(
"resource-org.springframework.boot.context.properties.scan.valid.a.AScanConfiguration$MyResourceProperties"))
.isFalse();
}
private void load(Class<?>... classes) {
this.context.register(classes);
this.context.refresh();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment