|
|
|
@ -141,6 +141,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
|
|
|
* @author Madhura Bhave
|
|
|
|
|
* @author Brian Clozel
|
|
|
|
|
* @author Artsiom Yudovin
|
|
|
|
|
* @author Marten Deinum
|
|
|
|
|
*/
|
|
|
|
|
@ExtendWith(OutputCaptureExtension.class)
|
|
|
|
|
class SpringApplicationTests {
|
|
|
|
@ -1179,6 +1180,29 @@ class SpringApplicationTests {
|
|
|
|
|
assertThat(startCount).isEqualTo(endCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void customApplicationStartupPublishStartupStepsWithFailure() {
|
|
|
|
|
ApplicationStartup applicationStartup = mock(ApplicationStartup.class);
|
|
|
|
|
StartupStep startupStep = mock(StartupStep.class);
|
|
|
|
|
given(applicationStartup.start(anyString())).willReturn(startupStep);
|
|
|
|
|
given(startupStep.tag(anyString(), anyString())).willReturn(startupStep);
|
|
|
|
|
given(startupStep.tag(anyString(), ArgumentMatchers.<Supplier<String>>any())).willReturn(startupStep);
|
|
|
|
|
SpringApplication application = new SpringApplication(BrokenPostConstructConfig.class);
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
application.setApplicationStartup(applicationStartup);
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(application::run);
|
|
|
|
|
verify(applicationStartup).start("spring.boot.application.starting");
|
|
|
|
|
verify(applicationStartup).start("spring.boot.application.environment-prepared");
|
|
|
|
|
verify(applicationStartup).start("spring.boot.application.failed");
|
|
|
|
|
long startCount = mockingDetails(applicationStartup).getInvocations().stream()
|
|
|
|
|
.filter((invocation) -> invocation.getMethod().toString().contains("start(")).count();
|
|
|
|
|
long endCount = mockingDetails(startupStep).getInvocations().stream()
|
|
|
|
|
.filter((invocation) -> invocation.getMethod().toString().contains("end(")).count();
|
|
|
|
|
assertThat(startCount).isEqualTo(endCount + 1); // Will be same after
|
|
|
|
|
// spring-framework #25572 is
|
|
|
|
|
// fixed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(
|
|
|
|
|
S state) {
|
|
|
|
|
return (argument) -> (argument instanceof AvailabilityChangeEvent<?>)
|
|
|
|
|