Merge branch '3.1.x'
Closes gh-37921
This commit is contained in:
@@ -65,7 +65,7 @@ class RestartApplicationListenerTests {
|
||||
|
||||
@Test
|
||||
void initializeWithReady() {
|
||||
testInitialize(false);
|
||||
testInitialize(false, new ImplicitlyEnabledRestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("args", ARGS);
|
||||
assertThat(Restarter.getInstance().isFinished()).isTrue();
|
||||
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), "rootContexts")).isNotEmpty();
|
||||
@@ -73,7 +73,7 @@ class RestartApplicationListenerTests {
|
||||
|
||||
@Test
|
||||
void initializeWithFail() {
|
||||
testInitialize(true);
|
||||
testInitialize(true, new ImplicitlyEnabledRestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("args", ARGS);
|
||||
assertThat(Restarter.getInstance().isFinished()).isTrue();
|
||||
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), "rootContexts")).isEmpty();
|
||||
@@ -82,7 +82,7 @@ class RestartApplicationListenerTests {
|
||||
@Test
|
||||
void disableWithSystemProperty(CapturedOutput output) {
|
||||
System.setProperty(ENABLED_PROPERTY, "false");
|
||||
testInitialize(false);
|
||||
testInitialize(false, new ImplicitlyEnabledRestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
|
||||
assertThat(output).contains("Restart disabled due to System property");
|
||||
}
|
||||
@@ -90,14 +90,28 @@ class RestartApplicationListenerTests {
|
||||
@Test
|
||||
void enableWithSystemProperty(CapturedOutput output) {
|
||||
System.setProperty(ENABLED_PROPERTY, "true");
|
||||
testInitialize(false);
|
||||
testInitialize(false, new ImplicitlyEnabledRestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", true);
|
||||
assertThat(output).contains("Restart enabled irrespective of application packaging due to System property");
|
||||
}
|
||||
|
||||
private void testInitialize(boolean failed) {
|
||||
@Test
|
||||
void enableWithSystemPropertyWhenImplicitlyDisabled(CapturedOutput output) {
|
||||
System.setProperty(ENABLED_PROPERTY, "true");
|
||||
testInitialize(false, new RestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", true);
|
||||
assertThat(output).contains("Restart enabled irrespective of application packaging due to System property");
|
||||
}
|
||||
|
||||
@Test
|
||||
void implicitlyDisabledInTests(CapturedOutput output) {
|
||||
testInitialize(false, new RestartApplicationListener());
|
||||
assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
|
||||
assertThat(output).contains("Restart disabled due to context in which it is running");
|
||||
}
|
||||
|
||||
private void testInitialize(boolean failed, RestartApplicationListener listener) {
|
||||
Restarter.clearInstance();
|
||||
RestartApplicationListener listener = new RestartApplicationListener();
|
||||
DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
|
||||
SpringApplication application = new SpringApplication();
|
||||
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
|
||||
@@ -113,4 +127,13 @@ class RestartApplicationListenerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImplicitlyEnabledRestartApplicationListener extends RestartApplicationListener {
|
||||
|
||||
@Override
|
||||
boolean implicitlyEnableRestart() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -37,6 +38,7 @@ import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles;
|
||||
import org.springframework.boot.test.system.CapturedOutput;
|
||||
import org.springframework.boot.test.system.OutputCaptureExtension;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
@@ -44,6 +46,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.as;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
@@ -90,6 +93,14 @@ class RestarterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDisabled() {
|
||||
Restarter.disable();
|
||||
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
|
||||
Restarter.getInstance().prepare(context);
|
||||
assertThat(Restarter.getInstance()).extracting("rootContexts", as(InstanceOfAssertFactories.LIST)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
void getOrAddAttributeWithNewAttribute() {
|
||||
|
||||
Reference in New Issue
Block a user