|
38 | 38 | import org.junit.Test;
|
39 | 39 | import org.junit.rules.ExpectedException;
|
40 | 40 | import org.mockito.ArgumentCaptor;
|
| 41 | +import org.mockito.ArgumentMatchers; |
| 42 | +import org.mockito.InOrder; |
| 43 | +import org.mockito.Mockito; |
41 | 44 | import reactor.core.publisher.Mono;
|
42 | 45 |
|
43 | 46 | import org.springframework.beans.BeansException;
|
@@ -582,6 +585,33 @@ public void runCommandLineRunnersAndApplicationRunners() throws Exception {
|
582 | 585 | assertThat(this.context).has(runTestRunnerBean("runnerC"));
|
583 | 586 | }
|
584 | 587 |
|
| 588 | + @Test |
| 589 | + @SuppressWarnings("unchecked") |
| 590 | + public void runnersAreCalledAfterApplicationReadyEventIsPublished() throws Exception { |
| 591 | + SpringApplication application = new SpringApplication( |
| 592 | + MockRunnerConfiguration.class); |
| 593 | + application.setWebApplicationType(WebApplicationType.NONE); |
| 594 | + ApplicationListener<ApplicationReadyEvent> eventListener = mock( |
| 595 | + ApplicationListener.class); |
| 596 | + application.addListeners(eventListener); |
| 597 | + this.context = application.run(); |
| 598 | + ApplicationRunner applicationRunner = this.context |
| 599 | + .getBean(ApplicationRunner.class); |
| 600 | + CommandLineRunner commandLineRunner = this.context |
| 601 | + .getBean(CommandLineRunner.class); |
| 602 | + InOrder applicationRunnerOrder = Mockito.inOrder(eventListener, |
| 603 | + applicationRunner); |
| 604 | + applicationRunnerOrder.verify(eventListener) |
| 605 | + .onApplicationEvent(ArgumentMatchers.any(ApplicationReadyEvent.class)); |
| 606 | + applicationRunnerOrder.verify(applicationRunner) |
| 607 | + .run(ArgumentMatchers.any(ApplicationArguments.class)); |
| 608 | + InOrder commandLineRunnerOrder = Mockito.inOrder(eventListener, |
| 609 | + commandLineRunner); |
| 610 | + commandLineRunnerOrder.verify(eventListener) |
| 611 | + .onApplicationEvent(ArgumentMatchers.any(ApplicationReadyEvent.class)); |
| 612 | + commandLineRunnerOrder.verify(commandLineRunner).run(); |
| 613 | + } |
| 614 | + |
585 | 615 | @Test
|
586 | 616 | public void loadSources() throws Exception {
|
587 | 617 | Class<?>[] sources = { ExampleConfig.class, TestCommandLineRunner.class };
|
@@ -1217,6 +1247,21 @@ public void fail() {
|
1217 | 1247 |
|
1218 | 1248 | }
|
1219 | 1249 |
|
| 1250 | + @Configuration |
| 1251 | + static class MockRunnerConfiguration { |
| 1252 | + |
| 1253 | + @Bean |
| 1254 | + public CommandLineRunner commandLineRunner() { |
| 1255 | + return mock(CommandLineRunner.class); |
| 1256 | + } |
| 1257 | + |
| 1258 | + @Bean |
| 1259 | + public ApplicationRunner applicationRunner() { |
| 1260 | + return mock(ApplicationRunner.class); |
| 1261 | + } |
| 1262 | + |
| 1263 | + } |
| 1264 | + |
1220 | 1265 | static class ExitStatusException extends RuntimeException
|
1221 | 1266 | implements ExitCodeGenerator {
|
1222 | 1267 |
|
|
0 commit comments