From 3a5e0593872862a2f7eabacccb23cb7d6a8d6312 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Thu, 27 Feb 2025 00:37:39 +0900 Subject: [PATCH] Polish See gh-44447 Signed-off-by: Johnny Lim --- .../boot/autoconfigure/AutoConfigureBefore.java | 2 +- .../context/ServletWebServerApplicationContext.java | 12 ++++++------ .../ReactiveWebServerApplicationContextTests.java | 3 ++- .../ServletWebServerApplicationContextTests.java | 3 ++- .../server/AbstractServletWebServerFactoryTests.java | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java index 3a21439df3c..dfa81a438c5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigureBefore.java @@ -44,7 +44,7 @@ import org.springframework.context.annotation.DependsOn; public @interface AutoConfigureBefore { /** - * The auto-configure classes that should have not yet been applied. + * The auto-configuration classes that should have not yet been applied. * @return the classes */ Class[] value() default {}; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java index cc8e6a9650b..45e3958d1d0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContext.java @@ -146,15 +146,15 @@ public class ServletWebServerApplicationContext extends GenericWebApplicationCon super.refresh(); } catch (RuntimeException ex) { - try { - WebServer webServer = this.webServer; - if (webServer != null) { + WebServer webServer = this.webServer; + if (webServer != null) { + try { webServer.stop(); webServer.destroy(); } - } - catch (RuntimeException stopOrDestroyEx) { - ex.addSuppressed(stopOrDestroyEx); + catch (RuntimeException stopOrDestroyEx) { + ex.addSuppressed(stopOrDestroyEx); + } } throw ex; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java index 1c91af3fe14..01809b3bfb0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/context/ReactiveWebServerApplicationContextTests.java @@ -44,6 +44,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.then; import static org.mockito.BDDMockito.willThrow; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; /** @@ -148,7 +149,7 @@ class ReactiveWebServerApplicationContextTests { .withStackTraceContaining("WebServer has failed to stop"); WebServer webServer = this.context.getWebServer(); then(webServer).should().stop(); - then(webServer).should(times(0)).destroy(); + then(webServer).should(never()).destroy(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java index d474256bf60..9b78cc1fe64 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/context/ServletWebServerApplicationContextTests.java @@ -86,6 +86,7 @@ import static org.mockito.BDDMockito.willThrow; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.withSettings; @@ -236,7 +237,7 @@ class ServletWebServerApplicationContextTests { .withStackTraceContaining("WebServer has failed to stop"); WebServer webServer = this.context.getWebServer(); then(webServer).should().stop(); - then(webServer).should(times(0)).destroy(); + then(webServer).should(never()).destroy(); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index 0b3329fd732..c3eb610bc37 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -166,7 +166,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; +import static org.mockito.Mockito.never; /** * Base for testing classes that extends {@link AbstractServletWebServerFactory}. @@ -1195,7 +1195,7 @@ public abstract class AbstractServletWebServerFactoryTests { this.webServer = getFactory().getWebServer((servletContext) -> servletContext.addListener(listener)); this.webServer.start(); this.webServer.stop(); - then(listener).should(times(0)).contextDestroyed(any(ServletContextEvent.class)); + then(listener).should(never()).contextDestroyed(any(ServletContextEvent.class)); } @Test