@ -39,6 +39,7 @@ import static org.junit.Assert.assertThat;
* Tests for { @link ResourceBanner } .
*
* @author Phillip Webb
* @author Vedran Pavic
* /
public class ResourceBannerTests {
@ -51,7 +52,7 @@ public class ResourceBannerTests {
public void renderVersions ( ) throws Exception {
Resource resource = new ByteArrayResource (
"banner ${a} ${spring-boot.version} ${application.version}" . getBytes ( ) ) ;
String banner = printBanner ( resource , "10.2" , "2.0" );
String banner = printBanner ( resource , "10.2" , "2.0" , null );
assertThat ( banner , startsWith ( "banner 1 10.2 2.0" ) ) ;
}
@ -59,7 +60,7 @@ public class ResourceBannerTests {
public void renderWithoutVersions ( ) throws Exception {
Resource resource = new ByteArrayResource (
"banner ${a} ${spring-boot.version} ${application.version}" . getBytes ( ) ) ;
String banner = printBanner ( resource , null , null );
String banner = printBanner ( resource , null , null , null );
assertThat ( banner , startsWith ( "banner 1 " ) ) ;
}
@ -68,7 +69,7 @@ public class ResourceBannerTests {
Resource resource = new ByteArrayResource (
"banner ${a}${spring-boot.formatted-version}${application.formatted-version}"
. getBytes ( ) ) ;
String banner = printBanner ( resource , "10.2" , "2.0" );
String banner = printBanner ( resource , "10.2" , "2.0" , null );
assertThat ( banner , startsWith ( "banner 1 (v10.2) (v2.0)" ) ) ;
}
@ -77,7 +78,7 @@ public class ResourceBannerTests {
Resource resource = new ByteArrayResource (
"banner ${a}${spring-boot.formatted-version}${application.formatted-version}"
. getBytes ( ) ) ;
String banner = printBanner ( resource , null , null );
String banner = printBanner ( resource , null , null , null );
assertThat ( banner , startsWith ( "banner 1" ) ) ;
}
@ -86,7 +87,7 @@ public class ResourceBannerTests {
Resource resource = new ByteArrayResource (
"${Ansi.RED}This is red.${Ansi.NORMAL}" . getBytes ( ) ) ;
AnsiOutput . setEnabled ( AnsiOutput . Enabled . ALWAYS ) ;
String banner = printBanner ( resource , null , null );
String banner = printBanner ( resource , null , null , null );
assertThat ( banner , startsWith ( "\u001B[31mThis is red.\u001B[0m" ) ) ;
}
@ -95,14 +96,30 @@ public class ResourceBannerTests {
Resource resource = new ByteArrayResource (
"${Ansi.RED}This is red.${Ansi.NORMAL}" . getBytes ( ) ) ;
AnsiOutput . setEnabled ( AnsiOutput . Enabled . NEVER ) ;
String banner = printBanner ( resource , null , null );
String banner = printBanner ( resource , null , null , null );
assertThat ( banner , startsWith ( "This is red." ) ) ;
}
@Test
public void renderWithTitle ( ) throws Exception {
Resource resource = new ByteArrayResource (
"banner ${application.title} ${a}" . getBytes ( ) ) ;
String banner = printBanner ( resource , null , null , "title" ) ;
assertThat ( banner , startsWith ( "banner title 1" ) ) ;
}
@Test
public void renderWithoutTitle ( ) throws Exception {
Resource resource = new ByteArrayResource (
"banner ${application.title} ${a}" . getBytes ( ) ) ;
String banner = printBanner ( resource , null , null , null ) ;
assertThat ( banner , startsWith ( "banner 1" ) ) ;
}
private String printBanner ( Resource resource , String bootVersion ,
String applicationVersion ) {
String applicationVersion , String applicationTitle ) {
ResourceBanner banner = new MockResourceBanner ( resource , bootVersion ,
applicationVersion ) ;
applicationVersion , applicationTitle );
ConfigurableEnvironment environment = new MockEnvironment ( ) ;
Map < String , Object > source = Collections . < String , Object > singletonMap ( "a" , "1" ) ;
environment . getPropertySources ( ) . addLast ( new MapPropertySource ( "map" , source ) ) ;
@ -117,11 +134,14 @@ public class ResourceBannerTests {
private final String applicationVersion ;
private final String applicationTitle ;
MockResourceBanner ( Resource resource , String bootVersion ,
String applicationVersion ) {
String applicationVersion , String applicationTitle ) {
super ( resource ) ;
this . bootVersion = bootVersion ;
this . applicationVersion = applicationVersion ;
this . applicationTitle = applicationTitle ;
}
@Override
@ -134,6 +154,11 @@ public class ResourceBannerTests {
return this . applicationVersion ;
}
@Override
protected String getApplicationTitle ( Class < ? > sourceClass ) {
return this . applicationTitle ;
}
}
}