|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
@ -105,7 +105,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.isA;
|
|
|
|
|
import static org.mockito.BDDMockito.willThrow;
|
|
|
|
|
import static org.mockito.Mockito.atLeastOnce;
|
|
|
|
@ -766,17 +765,11 @@ public class SpringApplicationTests {
|
|
|
|
|
ExitStatusException failure = new ExitStatusException();
|
|
|
|
|
willThrow(failure).given(listener)
|
|
|
|
|
.onApplicationEvent(isA(ApplicationReadyEvent.class));
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Run should have failed with a RuntimeException");
|
|
|
|
|
}
|
|
|
|
|
catch (RuntimeException ex) {
|
|
|
|
|
verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class));
|
|
|
|
|
verify(listener, never())
|
|
|
|
|
.onApplicationEvent(isA(ApplicationFailedEvent.class));
|
|
|
|
|
assertThat(exitCodeListener.getExitCode()).isEqualTo(11);
|
|
|
|
|
assertThat(this.output.toString()).contains("Application run failed");
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(RuntimeException.class).isThrownBy(application::run);
|
|
|
|
|
verify(listener).onApplicationEvent(isA(ApplicationReadyEvent.class));
|
|
|
|
|
verify(listener, never()).onApplicationEvent(isA(ApplicationFailedEvent.class));
|
|
|
|
|
assertThat(exitCodeListener.getExitCode()).isEqualTo(11);
|
|
|
|
|
assertThat(this.output.toString()).contains("Application run failed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -851,12 +844,7 @@ public class SpringApplicationTests {
|
|
|
|
|
ExitCodeListener listener = new ExitCodeListener();
|
|
|
|
|
application.addListeners(listener);
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Did not throw");
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalStateException ex) {
|
|
|
|
|
}
|
|
|
|
|
assertThatIllegalStateException().isThrownBy(application::run);
|
|
|
|
|
verify(handler).registerExitCode(11);
|
|
|
|
|
assertThat(listener.getExitCode()).isEqualTo(11);
|
|
|
|
|
}
|
|
|
|
@ -876,12 +864,7 @@ public class SpringApplicationTests {
|
|
|
|
|
ExitCodeListener listener = new ExitCodeListener();
|
|
|
|
|
application.addListeners(listener);
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Did not throw");
|
|
|
|
|
}
|
|
|
|
|
catch (IllegalStateException ex) {
|
|
|
|
|
}
|
|
|
|
|
assertThatIllegalStateException().isThrownBy(application::run);
|
|
|
|
|
verify(handler).registerExitCode(11);
|
|
|
|
|
assertThat(listener.getExitCode()).isEqualTo(11);
|
|
|
|
|
}
|
|
|
|
@ -901,12 +884,7 @@ public class SpringApplicationTests {
|
|
|
|
|
ExitCodeListener listener = new ExitCodeListener();
|
|
|
|
|
application.addListeners(listener);
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Did not throw");
|
|
|
|
|
}
|
|
|
|
|
catch (RuntimeException ex) {
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(RuntimeException.class).isThrownBy(application::run);
|
|
|
|
|
ArgumentCaptor<RuntimeException> exceptionCaptor = ArgumentCaptor
|
|
|
|
|
.forClass(RuntimeException.class);
|
|
|
|
|
verify(handler).registerLoggedException(exceptionCaptor.capture());
|
|
|
|
@ -994,16 +972,12 @@ public class SpringApplicationTests {
|
|
|
|
|
ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
|
|
|
|
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
|
|
|
|
application.addListeners(listener);
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Run should have failed with an ApplicationContextException");
|
|
|
|
|
}
|
|
|
|
|
catch (ApplicationContextException ex) {
|
|
|
|
|
verifyListenerEvents(listener, ApplicationStartingEvent.class,
|
|
|
|
|
ApplicationEnvironmentPreparedEvent.class,
|
|
|
|
|
ApplicationContextInitializedEvent.class,
|
|
|
|
|
ApplicationPreparedEvent.class, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(ApplicationContextException.class)
|
|
|
|
|
.isThrownBy(application::run);
|
|
|
|
|
verifyListenerEvents(listener, ApplicationStartingEvent.class,
|
|
|
|
|
ApplicationEnvironmentPreparedEvent.class,
|
|
|
|
|
ApplicationContextInitializedEvent.class, ApplicationPreparedEvent.class,
|
|
|
|
|
ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@ -1014,16 +988,12 @@ public class SpringApplicationTests {
|
|
|
|
|
BrokenPostConstructConfig.class);
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
application.addListeners(listener);
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Run should have failed with a BeanCreationException");
|
|
|
|
|
}
|
|
|
|
|
catch (BeanCreationException ex) {
|
|
|
|
|
verifyListenerEvents(listener, ApplicationStartingEvent.class,
|
|
|
|
|
ApplicationEnvironmentPreparedEvent.class,
|
|
|
|
|
ApplicationContextInitializedEvent.class,
|
|
|
|
|
ApplicationPreparedEvent.class, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(application::run);
|
|
|
|
|
verifyListenerEvents(listener, ApplicationStartingEvent.class,
|
|
|
|
|
ApplicationEnvironmentPreparedEvent.class,
|
|
|
|
|
ApplicationContextInitializedEvent.class, ApplicationPreparedEvent.class,
|
|
|
|
|
ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@ -1034,13 +1004,9 @@ public class SpringApplicationTests {
|
|
|
|
|
SpringApplication application = new SpringApplication(ExampleConfig.class);
|
|
|
|
|
application.addInitializers((applicationContext) -> applicationContext
|
|
|
|
|
.addApplicationListener(listener));
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Run should have failed with an ApplicationContextException");
|
|
|
|
|
}
|
|
|
|
|
catch (ApplicationContextException ex) {
|
|
|
|
|
verifyListenerEvents(listener, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(ApplicationContextException.class)
|
|
|
|
|
.isThrownBy(application::run);
|
|
|
|
|
verifyListenerEvents(listener, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@ -1052,13 +1018,9 @@ public class SpringApplicationTests {
|
|
|
|
|
application.setWebApplicationType(WebApplicationType.NONE);
|
|
|
|
|
application.addInitializers((applicationContext) -> applicationContext
|
|
|
|
|
.addApplicationListener(listener));
|
|
|
|
|
try {
|
|
|
|
|
application.run();
|
|
|
|
|
fail("Run should have failed with a BeanCreationException");
|
|
|
|
|
}
|
|
|
|
|
catch (BeanCreationException ex) {
|
|
|
|
|
verifyListenerEvents(listener, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class)
|
|
|
|
|
.isThrownBy(application::run);
|
|
|
|
|
verifyListenerEvents(listener, ApplicationFailedEvent.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|