@ -33,6 +33,7 @@ import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.WebApplicationContext ;
import org.springframework.web.context.WebApplicationContext ;
import static org.hamcrest.Matchers.equalTo ;
import static org.hamcrest.Matchers.equalTo ;
import static org.hamcrest.Matchers.is ;
import static org.junit.Assert.assertThat ;
import static org.junit.Assert.assertThat ;
/ * *
/ * *
@ -72,6 +73,13 @@ public class SpringBootServletInitializerTests {
equalToSet ( Config . class , ErrorPageFilter . class ) ) ;
equalToSet ( Config . class , ErrorPageFilter . class ) ) ;
}
}
@Test
public void applicationBuilderCanBeCustomized ( ) throws Exception {
CustomSpringBootServletInitializer servletInitializer = new CustomSpringBootServletInitializer ( ) ;
servletInitializer . createRootApplicationContext ( this . servletContext ) ;
assertThat ( servletInitializer . applicationBuilder . built , is ( true ) ) ;
}
private Matcher < ? super Set < Object > > equalToSet ( Object . . . items ) {
private Matcher < ? super Set < Object > > equalToSet ( Object . . . items ) {
Set < Object > set = new LinkedHashSet < Object > ( ) ;
Set < Object > set = new LinkedHashSet < Object > ( ) ;
Collections . addAll ( set , items ) ;
Collections . addAll ( set , items ) ;
@ -88,6 +96,22 @@ public class SpringBootServletInitializerTests {
}
}
private class CustomSpringBootServletInitializer extends
MockSpringBootServletInitializer {
private final CustomSpringApplicationBuilder applicationBuilder = new CustomSpringApplicationBuilder ( ) ;
@Override
protected SpringApplicationBuilder createSpringApplicationBuilder ( ) {
return this . applicationBuilder ;
}
@Override
protected SpringApplicationBuilder configure ( SpringApplicationBuilder application ) {
return application . sources ( Config . class ) ;
}
}
@Configuration
@Configuration
public class WithConfigurationAnnotation extends MockSpringBootServletInitializer {
public class WithConfigurationAnnotation extends MockSpringBootServletInitializer {
}
}
@ -106,4 +130,16 @@ public class SpringBootServletInitializerTests {
}
}
private static class CustomSpringApplicationBuilder extends SpringApplicationBuilder {
private boolean built ;
@Override
public SpringApplication build ( ) {
this . built = true ;
return super . build ( ) ;
}
}
}
}