|
|
|
@ -21,14 +21,24 @@ import java.io.PrintStream;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
|
import org.mockito.Captor;
|
|
|
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.Banner.Mode;
|
|
|
|
|
import org.springframework.boot.testutil.InternalOutputCapture;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.mockito.Matchers.any;
|
|
|
|
|
import static org.mockito.Matchers.eq;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.reset;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tests for {@link Banner} and its usage by {@link SpringApplication}.
|
|
|
|
@ -37,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
* @author Michael Stummvoll
|
|
|
|
|
* @author Michael Simons
|
|
|
|
|
*/
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class)
|
|
|
|
|
public class BannerTests {
|
|
|
|
|
|
|
|
|
|
private ConfigurableApplicationContext context;
|
|
|
|
@ -51,6 +62,9 @@ public class BannerTests {
|
|
|
|
|
@Rule
|
|
|
|
|
public InternalOutputCapture out = new InternalOutputCapture();
|
|
|
|
|
|
|
|
|
|
@Captor
|
|
|
|
|
private ArgumentCaptor<Class<?>> sourceClassCaptor;
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testDefaultBanner() throws Exception {
|
|
|
|
|
SpringApplication application = new SpringApplication(Config.class);
|
|
|
|
@ -88,10 +102,18 @@ public class BannerTests {
|
|
|
|
|
public void testCustomBannerInContext() throws Exception {
|
|
|
|
|
SpringApplication application = new SpringApplication(Config.class);
|
|
|
|
|
application.setWebEnvironment(false);
|
|
|
|
|
final DummyBanner dummyBanner = new DummyBanner();
|
|
|
|
|
application.setBanner(dummyBanner);
|
|
|
|
|
Banner banner = mock(Banner.class);
|
|
|
|
|
application.setBanner(banner);
|
|
|
|
|
this.context = application.run();
|
|
|
|
|
assertThat(this.context.getBean("springBootBanner")).isEqualTo(dummyBanner);
|
|
|
|
|
Banner printedBanner = (Banner) this.context.getBean("springBootBanner");
|
|
|
|
|
assertThat(ReflectionTestUtils.getField(printedBanner, "banner"))
|
|
|
|
|
.isEqualTo(banner);
|
|
|
|
|
verify(banner).printBanner(any(Environment.class),
|
|
|
|
|
this.sourceClassCaptor.capture(), any(PrintStream.class));
|
|
|
|
|
reset(banner);
|
|
|
|
|
printedBanner.printBanner(this.context.getEnvironment(), null, System.out);
|
|
|
|
|
verify(banner).printBanner(any(Environment.class),
|
|
|
|
|
eq(this.sourceClassCaptor.getValue()), any(PrintStream.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|