Home / Class/ ConfigDataTests Class — spring-boot Architecture

ConfigDataTests Class — spring-boot Architecture

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

Entity Profile

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataTests.java lines 42–137

class ConfigDataTests {

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenPropertySourcesIsNullThrowsException() {
		assertThatIllegalArgumentException().isThrownBy(() -> new ConfigData(null))
			.withMessage("'propertySources' must not be null");
	}

	@Test
	@SuppressWarnings("NullAway") // Test null check
	void createWhenOptionsIsNullThrowsException() {
		assertThatIllegalArgumentException().isThrownBy(() -> new ConfigData(Collections.emptyList(), (Option[]) null))
			.withMessage("'options' must not be null");
	}

	@Test
	void getPropertySourcesReturnsCopyOfSources() {
		MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
		List<MapPropertySource> sources = new ArrayList<>(Collections.singleton(source));
		ConfigData configData = new ConfigData(sources);
		sources.clear();
		assertThat(configData.getPropertySources()).containsExactly(source);
	}

	@Test
	void getOptionsWhenOptionsSetAtConstructionAlwaysReturnsSameOptions() {
		MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
		ConfigData configData = new ConfigData(Collections.singleton(source), Option.IGNORE_IMPORTS);
		assertThat(configData.getOptions(source).asSet()).containsExactly(Option.IGNORE_IMPORTS);
	}

	@Test
	void getOptionsReturnsOptionsFromPropertySourceOptions() {
		MapPropertySource source1 = new MapPropertySource("test", Collections.emptyMap());
		MapPropertySource source2 = new MapPropertySource("test", Collections.emptyMap());
		Options options1 = Options.of(Option.IGNORE_IMPORTS);
		Options options2 = Options.of(Option.IGNORE_PROFILES);
		PropertySourceOptions propertySourceOptions = (source) -> (source != source1) ? options2 : options1;
		ConfigData configData = new ConfigData(Arrays.asList(source1, source2), propertySourceOptions);
		assertThat(configData.getOptions(source1)).isEqualTo(options1);
		assertThat(configData.getOptions(source2)).isEqualTo(options2);
	}

	@Test
	void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
		MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
		PropertySourceOptions propertySourceOptions = (propertySource) -> null;
		ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
		assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
	}

	@Test
	void optionsOfCreatesOptions() {
		Options options = Options.of(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
		assertThat(options.asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
	}

	@Test
	void optionsOfUsesCopyOfOptions() {
		Option[] array = { Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES };
		Options options = Options.of(array);
		array[0] = Option.PROFILE_SPECIFIC;
		assertThat(options.asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
	}

	@Test
	void optionsNoneReturnsEmptyOptions() {
		assertThat(Options.NONE.asSet()).isEmpty();
	}

	@Test
	void optionsWithoutReturnsNewOptions() {
		Options options = Options.of(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
		Options without = options.without(Option.IGNORE_PROFILES);
		assertThat(options.asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
		assertThat(without.asSet()).containsExactly(Option.IGNORE_IMPORTS);
	}

	@Test
	void optionsWithReturnsNewOptions() {
		Options options = Options.of(Option.IGNORE_IMPORTS);
		Options with = options.with(Option.IGNORE_PROFILES);
		assertThat(options.asSet()).containsExactly(Option.IGNORE_IMPORTS);
		assertThat(with.asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
	}

	@Test
	void propertySourceOptionsAlwaysReturnsSameOptionsEachTime() {
		PropertySourceOptions options = PropertySourceOptions.always(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
		Options propertySourceOptions = options.get(mock(PropertySource.class));
		assertThat(propertySourceOptions).isNotNull();
		assertThat(propertySourceOptions.asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
	}

}

Analyze Your Own Codebase

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

Try Supermodel Free