Polish 'Allow step action to be optional'

See gh-22845
pull/22898/head
Phillip Webb 4 years ago
parent 0e5be0ab62
commit a062b51efb

@ -103,15 +103,16 @@ class SpringApplicationRunListeners {
}
private void doWithListeners(String stepName, Consumer<SpringApplicationRunListener> listenerAction) {
doWithListeners(stepName, listenerAction, (step) -> {
});
doWithListeners(stepName, listenerAction, null);
}
private void doWithListeners(String stepName, Consumer<SpringApplicationRunListener> listenerAction,
Consumer<StartupStep> stepAction) {
StartupStep step = this.applicationStartup.start(stepName);
this.listeners.forEach(listenerAction);
stepAction.accept(step);
if (stepAction != null) {
stepAction.accept(step);
}
step.end();
}

@ -1191,16 +1191,16 @@ class SpringApplicationTests {
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);
assertThat(startCount).isEqualTo(endCount + 1); // Will be same after
// spring-framework #25572 is
// fixed
}
private <S extends AvailabilityState> ArgumentMatcher<ApplicationEvent> isAvailabilityChangeEventWithState(

Loading…
Cancel
Save