@ -82,6 +82,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat ;
import static org.junit.Assert.assertThat ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.assertTrue ;
import static org.mockito.Matchers.anyObject ;
import static org.mockito.Matchers.anyObject ;
import static org.mockito.Mockito.atLeastOnce ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.never ;
import static org.mockito.Mockito.never ;
import static org.mockito.Mockito.spy ;
import static org.mockito.Mockito.spy ;
@ -95,6 +96,7 @@ import static org.mockito.Mockito.verify;
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Christian Dupuis
* @author Christian Dupuis
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Jeremy Rickard
* /
* /
public class SpringApplicationTests {
public class SpringApplicationTests {
@ -164,7 +166,7 @@ public class SpringApplicationTests {
public void disableBanner ( ) throws Exception {
public void disableBanner ( ) throws Exception {
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
application . setWebEnvironment ( false ) ;
application . setWebEnvironment ( false ) ;
application . setShowBanner ( false ) ;
application . setShowBanner ( Banner . Mode . OFF ) ;
this . context = application . run ( ) ;
this . context = application . run ( ) ;
verify ( application , never ( ) ) . printBanner ( ( Environment ) anyObject ( ) ) ;
verify ( application , never ( ) ) . printBanner ( ( Environment ) anyObject ( ) ) ;
}
}
@ -173,7 +175,7 @@ public class SpringApplicationTests {
public void disableBannerViaProperty ( ) throws Exception {
public void disableBannerViaProperty ( ) throws Exception {
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
application . setWebEnvironment ( false ) ;
application . setWebEnvironment ( false ) ;
this . context = application . run ( "--spring.main.show_banner= false ") ;
this . context = application . run ( "--spring.main.show_banner= OFF ") ;
verify ( application , never ( ) ) . printBanner ( ( Environment ) anyObject ( ) ) ;
verify ( application , never ( ) ) . printBanner ( ( Environment ) anyObject ( ) ) ;
}
}
@ -213,6 +215,24 @@ public class SpringApplicationTests {
containsString ( "The following profiles are active: myprofile" ) ) ;
containsString ( "The following profiles are active: myprofile" ) ) ;
}
}
@Test
public void enableBannerInLogViaProperty ( ) throws Exception {
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
application . setWebEnvironment ( false ) ;
this . context = application . run ( "--spring.main.show_banner=LOG" ) ;
verify ( application , atLeastOnce ( ) ) . setShowBanner ( Banner . Mode . LOG ) ;
}
@Test
public void verifyBannerOutputContainsLogInfo ( ) throws Exception {
SpringApplication application = spy ( new SpringApplication ( ExampleConfig . class ) ) ;
application . setWebEnvironment ( false ) ;
application . run ( "--spring.main.show_banner=LOG" ,
"--banner.location=classpath:test-banner.txt" ) ;
verify ( application , atLeastOnce ( ) ) . setShowBanner ( Banner . Mode . LOG ) ;
assertThat ( this . output . toString ( ) , containsString ( "o.s.boot.SpringApplication" ) ) ;
}
@Test
@Test
public void customId ( ) throws Exception {
public void customId ( ) throws Exception {
SpringApplication application = new SpringApplication ( ExampleConfig . class ) ;
SpringApplication application = new SpringApplication ( ExampleConfig . class ) ;
@ -545,8 +565,8 @@ public class SpringApplicationTests {
TestSpringApplication application = new TestSpringApplication (
TestSpringApplication application = new TestSpringApplication (
ExampleConfig . class ) ;
ExampleConfig . class ) ;
application . setWebEnvironment ( false ) ;
application . setWebEnvironment ( false ) ;
this . context = application . run ( "--spring.main.show_banner= false ") ;
this . context = application . run ( "--spring.main.show_banner= OFF ") ;
assertThat ( application . getShowBanner ( ) , is ( false ) ) ;
assertThat ( application . getShowBanner ( ) , is ( Banner . Mode . OFF ) ) ;
}
}
@Test
@Test
@ -713,7 +733,7 @@ public class SpringApplicationTests {
private boolean useMockLoader ;
private boolean useMockLoader ;
private boolean showBanner ;
private Banner . Mode showBanner ;
TestSpringApplication ( Object . . . sources ) {
TestSpringApplication ( Object . . . sources ) {
super ( sources ) ;
super ( sources ) ;
@ -744,12 +764,12 @@ public class SpringApplicationTests {
}
}
@Override
@Override
public void setShowBanner ( boolean showBanner ) {
public void setShowBanner ( Banner . Mode bannerMode ) {
super . setShowBanner ( showBanner ) ;
super . setShowBanner ( bannerMode ) ;
this . showBanner = showBanner ;
this . showBanner = bannerMode ;
}
}
public boolean getShowBanner ( ) {
public Banner . Mode getShowBanner ( ) {
return this . showBanner ;
return this . showBanner ;
}
}