ResourceBannerTests Class — spring-boot Architecture
Architecture documentation for the ResourceBannerTests class in ResourceBannerTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/ResourceBannerTests.java lines 49–244
class ResourceBannerTests {
@AfterEach
void reset() {
AnsiOutput.setEnabled(Enabled.DETECT);
}
@Test
void renderVersions() {
Resource resource = new ByteArrayResource(
"banner ${a} ${spring-boot.version} ${application.version}".getBytes());
String banner = printBanner(resource, "10.2", "2.0", null);
assertThat(banner).startsWith("banner 1 10.2 2.0");
}
@Test
void renderWithoutVersions() {
Resource resource = new ByteArrayResource(
"banner ${a} ${spring-boot.version} ${application.version}".getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner 1 ");
}
@Test
void renderWithoutVersionsWithDefaultValues() {
Resource resource = new ByteArrayResource(
"banner ${a} ${spring-boot.version:X.Y.Z} ${application.version:A.B.C}".getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner 1 X.Y.Z A.B.C");
}
@Test
void renderFormattedVersions() {
Resource resource = new ByteArrayResource(
"banner ${a}${spring-boot.formatted-version}${application.formatted-version}".getBytes());
String banner = printBanner(resource, "10.2", "2.0", null);
assertThat(banner).startsWith("banner 1 (v10.2) (v2.0)");
}
@Test
void renderWithoutFormattedVersions() {
Resource resource = new ByteArrayResource(
"banner ${a} ${spring-boot.formatted-version} ${application.formatted-version}".getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner 1 ");
}
@Test
void renderWithoutFormattedVersionsWithDefaultValues() {
Resource resource = new ByteArrayResource(
"banner ${a} ${spring-boot.formatted-version:(vX.Y.Z)} ${application.formatted-version:(vA.B.C)}"
.getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner 1 (vX.Y.Z) (vA.B.C)");
}
@Test
void renderWithColors() {
Resource resource = new ByteArrayResource("${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes());
AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS);
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("\u001B[31mThis is red.\u001B[0m");
}
@Test
void renderWithColorsButDisabled() {
Resource resource = new ByteArrayResource("${Ansi.RED}This is red.${Ansi.NORMAL}".getBytes());
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("This is red.");
}
@Test
void renderWith256Colors() {
Resource resource = new ByteArrayResource("${AnsiColor.208}This is orange.${Ansi.NORMAL}".getBytes());
AnsiOutput.setEnabled(AnsiOutput.Enabled.ALWAYS);
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("\033[38;5;208mThis is orange.\u001B[0m");
}
@Test
void renderWith256ColorsButDisabled() {
Resource resource = new ByteArrayResource("${AnsiColor.208}This is orange.${Ansi.NORMAL}".getBytes());
AnsiOutput.setEnabled(AnsiOutput.Enabled.NEVER);
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("This is orange.");
}
@Test
void renderWithTitle() {
Resource resource = new ByteArrayResource("banner ${application.title} ${a}".getBytes());
String banner = printBanner(resource, null, null, "title");
assertThat(banner).startsWith("banner title 1");
}
@Test
void renderWithoutTitle() {
Resource resource = new ByteArrayResource("banner ${application.title} ${a}".getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner 1");
}
@Test
void renderWithoutTitleWithDefaultValue() {
Resource resource = new ByteArrayResource("banner ${application.title:Default Title} ${a}".getBytes());
String banner = printBanner(resource, null, null, null);
assertThat(banner).startsWith("banner Default Title 1");
}
@Test
void renderWithDefaultValues() {
Resource resource = new ByteArrayResource(
"banner ${a:default-a} ${b:default-b} ${spring-boot.version:default-boot-version} ${application.version:default-application-version}"
.getBytes());
String banner = printBanner(resource, "10.2", "1.0", null);
assertThat(banner).startsWith("banner 1 default-b 10.2 1.0");
}
@Test
void renderWithMutation() {
Resource resource = new ByteArrayResource("banner ${foo}".getBytes());
String banner = printBanner(new MutatingResourceBanner(resource, "1", null), "2");
assertThat(banner).startsWith("banner bar");
}
private String printBanner(Resource resource, @Nullable String bootVersion, @Nullable String applicationVersion,
@Nullable String applicationTitle) {
return printBanner(new MockResourceBanner(resource, bootVersion, applicationTitle), applicationVersion);
}
private String printBanner(ResourceBanner banner, @Nullable String applicationVersion) {
MockEnvironment environment = new MockEnvironment();
if (applicationVersion != null) {
environment.setProperty("spring.application.version", applicationVersion);
}
Map<String, Object> source = Collections.singletonMap("a", "1");
environment.getPropertySources().addLast(new MapPropertySource("map", source));
ByteArrayOutputStream out = new ByteArrayOutputStream();
banner.printBanner(environment, getClass(), new PrintStream(out));
return out.toString();
}
static class MockResourceBanner extends ResourceBanner {
private final @Nullable String bootVersion;
private final @Nullable String applicationTitle;
MockResourceBanner(Resource resource, @Nullable String bootVersion, @Nullable String applicationTitle) {
super(resource);
this.bootVersion = bootVersion;
this.applicationTitle = applicationTitle;
}
@Override
protected @Nullable String getBootVersion() {
return this.bootVersion;
}
@Override
protected @Nullable String getApplicationTitle(@Nullable Class<?> sourceClass) {
return this.applicationTitle;
}
}
static class MutatingResourceBanner extends MockResourceBanner {
MutatingResourceBanner(Resource resource, String bootVersion, @Nullable String applicationTitle) {
super(resource, bootVersion, applicationTitle);
}
@Override
protected List<PropertyResolver> getPropertyResolvers(Environment environment, @Nullable Class<?> sourceClass) {
List<PropertyResolver> resolvers = super.getPropertyResolvers(environment, sourceClass);
PropertyResolver resolver = new AbstractPropertyResolver() {
@Override
@SuppressWarnings("unchecked")
public <T> @Nullable T getProperty(String key, Class<T> targetType) {
return String.class.equals(targetType) ? (T) getPropertyAsRawString(key) : null;
}
@Override
protected @Nullable String getPropertyAsRawString(String key) {
return ("foo".equals(key)) ? "bar" : null;
}
};
resolvers.add(resolver);
return resolvers;
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free