PropertySourceOriginTests Class — spring-boot Architecture
Architecture documentation for the PropertySourceOriginTests class in PropertySourceOriginTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/test/java/org/springframework/boot/origin/PropertySourceOriginTests.java lines 37–109
class PropertySourceOriginTests {
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenPropertySourceIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PropertySourceOrigin(null, "name"))
.withMessageContaining("'propertySource' must not be null");
}
@Test
@SuppressWarnings("NullAway") // Test null check
void createWhenPropertyNameIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new PropertySourceOrigin(mock(PropertySource.class), null))
.withMessageContaining("'propertyName' must not be empty");
}
@Test
void createWhenPropertyNameIsEmptyShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PropertySourceOrigin(mock(PropertySource.class), ""))
.withMessageContaining("'propertyName' must not be empty");
}
@Test
void getPropertySourceShouldReturnPropertySource() {
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
assertThat(origin.getPropertySource()).isEqualTo(propertySource);
}
@Test
void getPropertyNameShouldReturnPropertyName() {
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
assertThat(origin.getPropertyName()).isEqualTo("foo");
}
@Test
void toStringShouldShowDetails() {
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
assertThat(origin).hasToString("\"foo\" from property source \"test\"");
}
@Test
@SuppressWarnings("unchecked")
void getWhenPropertySourceSupportsOriginLookupShouldReturnOrigin() {
Origin origin = mock(Origin.class);
PropertySource<?> propertySource = mock(PropertySource.class,
withSettings().extraInterfaces(OriginLookup.class));
OriginLookup<String> originCapablePropertySource = (OriginLookup<String>) propertySource;
given(originCapablePropertySource.getOrigin("foo")).willReturn(origin);
Origin actual = PropertySourceOrigin.get(propertySource, "foo");
assertThat(actual).hasToString(origin.toString());
assertThat(((PropertySourceOrigin) actual).getOrigin()).isSameAs(origin);
}
@Test
void getWhenPropertySourceSupportsOriginLookupButNoOriginShouldWrap() {
PropertySource<?> propertySource = mock(PropertySource.class,
withSettings().extraInterfaces(OriginLookup.class));
assertThat(PropertySourceOrigin.get(propertySource, "foo")).isInstanceOf(PropertySourceOrigin.class);
}
@Test
void getWhenPropertySourceIsNotOriginAwareShouldWrap() {
MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
assertThat(origin.getPropertySource()).isEqualTo(propertySource);
assertThat(origin.getPropertyName()).isEqualTo("foo");
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free