@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 2021 the original author or authors .
* Copyright 2012 - 2023 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 .
@ -66,7 +66,7 @@ class RestartApplicationListenerTests {
@@ -66,7 +66,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 ( ) ;
@ -74,7 +74,7 @@ class RestartApplicationListenerTests {
@@ -74,7 +74,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 ( ) ;
@ -83,7 +83,7 @@ class RestartApplicationListenerTests {
@@ -83,7 +83,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" ) ;
}
@ -91,14 +91,28 @@ class RestartApplicationListenerTests {
@@ -91,14 +91,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 ) ;
@ -114,4 +128,13 @@ class RestartApplicationListenerTests {
@@ -114,4 +128,13 @@ class RestartApplicationListenerTests {
}
}
private static class ImplicitlyEnabledRestartApplicationListener extends RestartApplicationListener {
@Override
boolean implicitlyEnableRestart ( ) {
return true ;
}
}
}