use of org.springframework.boot.testsupport.system.CapturedOutput in project spring-boot by spring-projects.
the class SpringApplicationTests method runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished.
@Test
@SuppressWarnings("unchecked")
void runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished(CapturedOutput output) throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
ApplicationRunner applicationRunner = mock(ApplicationRunner.class);
CommandLineRunner commandLineRunner = mock(CommandLineRunner.class);
application.addInitializers((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("commandLineRunner", (CommandLineRunner) (args) -> {
assertThat(output).contains("Started");
commandLineRunner.run(args);
});
beanFactory.registerSingleton("applicationRunner", (ApplicationRunner) (args) -> {
assertThat(output).contains("Started");
applicationRunner.run(args);
});
});
application.setWebApplicationType(WebApplicationType.NONE);
ApplicationListener<ApplicationReadyEvent> eventListener = mock(ApplicationListener.class);
application.addListeners(eventListener);
this.context = application.run();
InOrder applicationRunnerOrder = Mockito.inOrder(eventListener, applicationRunner);
applicationRunnerOrder.verify(applicationRunner).run(any(ApplicationArguments.class));
applicationRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
InOrder commandLineRunnerOrder = Mockito.inOrder(eventListener, commandLineRunner);
commandLineRunnerOrder.verify(commandLineRunner).run();
commandLineRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
}
use of org.springframework.boot.testsupport.system.CapturedOutput in project spring-boot by spring-projects.
the class ErrorPageFilterTests method errorMessageForRequestWithPathInfo.
@Test
void errorMessageForRequestWithPathInfo(CapturedOutput output) throws IOException, ServletException {
this.request.setServletPath("/test");
this.request.setPathInfo("/alpha");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new RuntimeException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(output).contains("request [/test/alpha]");
}
use of org.springframework.boot.testsupport.system.CapturedOutput in project spring-boot by spring-projects.
the class ErrorPageFilterTests method responseCommittedWhenFromClientAbortException.
@Test
void responseCommittedWhenFromClientAbortException(CapturedOutput output) throws Exception {
this.filter.addErrorPages(new ErrorPage("/error"));
this.response.setCommitted(true);
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new ClientAbortException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(this.response.isCommitted()).isTrue();
assertThat(output).doesNotContain("Cannot forward");
}
use of org.springframework.boot.testsupport.system.CapturedOutput in project spring-boot by spring-projects.
the class ErrorPageFilterTests method errorMessageForRequestWithoutPathInfo.
@Test
void errorMessageForRequestWithoutPathInfo(CapturedOutput output) throws IOException, ServletException {
this.request.setServletPath("/test");
this.filter.addErrorPages(new ErrorPage("/error"));
this.chain = new TestFilterChain((request, response, chain) -> {
chain.call();
throw new RuntimeException();
});
this.filter.doFilter(this.request, this.response, this.chain);
assertThat(output).contains("request [/test]");
}
Aggregations