From 0c8ae65bd40c57b072ae85bea1c39e63266d068e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 18 Nov 2022 15:40:50 +0000 Subject: [PATCH] Switch of the banner when SpringBootTest runs an app with a parent Closes gh-33079 --- .../boot/test/context/SpringBootContextLoader.java | 4 ++++ .../context/SpringBootTestContextHierarchyTests.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java index 613e9c33e0..0d5ddd0176 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootContextLoader.java @@ -23,6 +23,7 @@ import java.util.List; import org.springframework.beans.BeanUtils; import org.springframework.boot.ApplicationContextFactory; +import org.springframework.boot.Banner.Mode; import org.springframework.boot.DefaultPropertiesPropertySource; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; @@ -129,6 +130,9 @@ public class SpringBootContextLoader extends AbstractContextLoader { } return ApplicationContextFactory.DEFAULT.create(type); }); + if (config.getParent() != null) { + application.setBannerMode(Mode.OFF); + } application.setInitializers(initializers); boolean customEnvironent = ReflectionUtils.findMethod(getClass(), "getEnvironment") .getDeclaringClass() != SpringBootContextLoader.class; diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestContextHierarchyTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestContextHierarchyTests.java index ffcc9dcf27..072be8eaeb 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestContextHierarchyTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/SpringBootTestContextHierarchyTests.java @@ -17,14 +17,19 @@ package org.springframework.boot.test.context; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.context.SpringBootTestContextHierarchyTests.ChildConfiguration; import org.springframework.boot.test.context.SpringBootTestContextHierarchyTests.ParentConfiguration; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextHierarchy; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link SpringBootTest @SpringBootTest} and * {@link ContextHierarchy @ContextHierarchy}. @@ -34,11 +39,12 @@ import org.springframework.test.context.ContextHierarchy; @SpringBootTest @ContextHierarchy({ @ContextConfiguration(classes = ParentConfiguration.class), @ContextConfiguration(classes = ChildConfiguration.class) }) +@ExtendWith(OutputCaptureExtension.class) class SpringBootTestContextHierarchyTests { @Test - void contextLoads() { - + void contextLoads(CapturedOutput capturedOutput) { + assertThat(capturedOutput).containsOnlyOnce(":: Spring Boot ::"); } @Configuration(proxyBeanMethods = false)