Home / Class/ ConfigurationPropertyCachingTests Class — spring-boot Architecture

ConfigurationPropertyCachingTests Class — spring-boot Architecture

Architecture documentation for the ConfigurationPropertyCachingTests class in ConfigurationPropertyCachingTests.java from the spring-boot codebase.

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyCachingTests.java lines 38–97

class ConfigurationPropertyCachingTests {

	private StandardEnvironment environment;

	private MapPropertySource propertySource;

	@BeforeEach
	void setup() {
		this.environment = new StandardEnvironment();
		this.propertySource = new MapPropertySource("test", Collections.singletonMap("spring", "boot"));
		this.environment.getPropertySources().addLast(this.propertySource);
	}

	@Test
	void getFromEnvironmentReturnsCaching() {
		ConfigurationPropertyCaching caching = ConfigurationPropertyCaching.get(this.environment);
		assertThat(caching).isInstanceOf(ConfigurationPropertySourcesCaching.class);
	}

	@Test
	void getFromEnvironmentForUnderlyingSourceReturnsCaching() {
		ConfigurationPropertyCaching caching = ConfigurationPropertyCaching.get(this.environment, this.propertySource);
		assertThat(caching).isInstanceOf(SoftReferenceConfigurationPropertyCache.class);
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void getFromSourcesWhenSourcesIsNullThrowsException() {
		assertThatIllegalArgumentException()
			.isThrownBy(() -> ConfigurationPropertyCaching.get((Iterable<ConfigurationPropertySource>) null))
			.withMessage("'sources' must not be null");
	}

	@Test
	void getFromSourcesReturnsCachingComposite() {
		List<ConfigurationPropertySource> sources = new ArrayList<>();
		sources.add(SpringConfigurationPropertySource.from(this.propertySource));
		ConfigurationPropertyCaching caching = ConfigurationPropertyCaching.get(sources);
		assertThat(caching).isInstanceOf(ConfigurationPropertySourcesCaching.class);
	}

	@Test
	void getFromSourcesForUnderlyingSourceReturnsCaching() {
		List<ConfigurationPropertySource> sources = new ArrayList<>();
		sources.add(SpringConfigurationPropertySource.from(this.propertySource));
		ConfigurationPropertyCaching caching = ConfigurationPropertyCaching.get(sources, this.propertySource);
		assertThat(caching).isInstanceOf(SoftReferenceConfigurationPropertyCache.class);
	}

	@Test
	void getFromSourcesForUnderlyingSourceWhenCantFindThrowsException() {
		List<ConfigurationPropertySource> sources = new ArrayList<>();
		sources.add(SpringConfigurationPropertySource.from(this.propertySource));
		MapPropertySource anotherPropertySource = new MapPropertySource("test2", Collections.emptyMap());
		assertThatIllegalStateException()
			.isThrownBy(() -> ConfigurationPropertyCaching.get(sources, anotherPropertySource))
			.withMessage("Unable to find cache from configuration property sources");
	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free