ConfigurationPropertySourcesCachingTests Class — spring-boot Architecture
Architecture documentation for the ConfigurationPropertySourcesCachingTests class in ConfigurationPropertySourcesCachingTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertySourcesCachingTests.java lines 37–116
class ConfigurationPropertySourcesCachingTests {
private List<ConfigurationPropertySource> sources;
private ConfigurationPropertySourcesCaching caching;
@BeforeEach
void setup() {
this.sources = new ArrayList<>();
for (int i = 0; i < 4; i++) {
this.sources.add(mockSource(i % 2 == 0));
}
this.caching = new ConfigurationPropertySourcesCaching(this.sources);
}
private ConfigurationPropertySource mockSource(boolean cachingSource) {
if (!cachingSource) {
return mock(ConfigurationPropertySource.class);
}
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().extraInterfaces(CachingConfigurationPropertySource.class));
ConfigurationPropertyCaching caching = mock(ConfigurationPropertyCaching.class);
given(((CachingConfigurationPropertySource) source).getCaching()).willReturn(caching);
return source;
}
@Test
void enableDelegatesToCachingConfigurationPropertySources() {
this.caching.enable();
then(getCaching(0)).should().enable();
then(getCaching(2)).should().enable();
}
@Test
void enableWhenSourcesIsNullDoesNothing() {
new ConfigurationPropertySourcesCaching(null).enable();
}
@Test
void disableDelegatesToCachingConfigurationPropertySources() {
this.caching.disable();
then(getCaching(0)).should().disable();
then(getCaching(2)).should().disable();
}
@Test
void disableWhenSourcesIsNullDoesNothing() {
new ConfigurationPropertySourcesCaching(null).disable();
}
@Test
void setTimeToLiveDelegatesToCachingConfigurationPropertySources() {
Duration ttl = Duration.ofDays(1);
this.caching.setTimeToLive(ttl);
then(getCaching(0)).should().setTimeToLive(ttl);
then(getCaching(2)).should().setTimeToLive(ttl);
}
@Test
void setTimeToLiveWhenSourcesIsNullDoesNothing() {
new ConfigurationPropertySourcesCaching(null).setTimeToLive(Duration.ofSeconds(1));
}
@Test
void clearDelegatesToCachingConfigurationPropertySources() {
this.caching.clear();
then(getCaching(0)).should().clear();
then(getCaching(2)).should().clear();
}
@Test
void clearWhenSourcesIsNullDoesNothing() {
new ConfigurationPropertySourcesCaching(null).enable();
}
private @Nullable ConfigurationPropertyCaching getCaching(int index) {
return CachingConfigurationPropertySource.find(this.sources.get(index));
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free