PropertySourcesDeducerTests Class — spring-boot Architecture
Architecture documentation for the PropertySourcesDeducerTests class in PropertySourcesDeducerTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertySourcesDeducerTests.java lines 44–128
class PropertySourcesDeducerTests {
@Test
void getPropertySourcesWhenHasSinglePropertySourcesPlaceholderConfigurerReturnsBean() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
PropertySourcesPlaceholderConfigurerConfiguration.class);
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
PropertySources propertySources = deducer.getPropertySources();
assertThat(propertySources.get("test")).isInstanceOf(TestPropertySource.class);
}
@Test
void getPropertySourcesWhenHasNoPropertySourcesPlaceholderConfigurerReturnsEnvironmentSources() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
environment.getPropertySources().addFirst(new TestPropertySource());
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
PropertySources propertySources = deducer.getPropertySources();
assertThat(propertySources.get("test")).isInstanceOf(TestPropertySource.class);
}
@Test
void getPropertySourcesWhenHasMultiplePropertySourcesPlaceholderConfigurerReturnsEnvironmentSources() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
MultiplePropertySourcesPlaceholderConfigurerConfiguration.class);
ConfigurableEnvironment environment = (ConfigurableEnvironment) applicationContext.getEnvironment();
environment.getPropertySources().addFirst(new TestPropertySource());
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
PropertySources propertySources = deducer.getPropertySources();
assertThat(propertySources.get("test")).isInstanceOf(TestPropertySource.class);
}
@Test
void getPropertySourcesWhenUnavailableThrowsException() {
ApplicationContext applicationContext = mock(ApplicationContext.class);
Environment environment = mock(Environment.class);
given(applicationContext.getEnvironment()).willReturn(environment);
PropertySourcesDeducer deducer = new PropertySourcesDeducer(applicationContext);
assertThatIllegalStateException().isThrownBy(deducer::getPropertySources)
.withMessage("Unable to obtain PropertySources from PropertySourcesPlaceholderConfigurer or Environment");
}
@Configuration(proxyBeanMethods = false)
static class PropertySourcesPlaceholderConfigurerConfiguration {
@Bean
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new TestPropertySource());
configurer.setPropertySources(propertySources);
return configurer;
}
}
@Configuration(proxyBeanMethods = false)
static class EmptyConfiguration {
}
@Configuration(proxyBeanMethods = false)
static class MultiplePropertySourcesPlaceholderConfigurerConfiguration {
@Bean
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer1() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer2() {
return new PropertySourcesPlaceholderConfigurer();
}
}
private static class TestPropertySource extends MapPropertySource {
TestPropertySource() {
super("test", Collections.emptyMap());
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free