diff --git a/core/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProvider.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProvider.java index 93e855a8af0a..1db7a364f8fd 100644 --- a/core/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProvider.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProvider.java @@ -56,8 +56,8 @@ public interface ApplicationContextAssertProvider extends ApplicationContext, AssertProvider>, Closeable { /** - * Return an assert for AspectJ. - * @return an AspectJ assert + * Return an assert for AssertJ. + * @return an AssertJ assert * @deprecated to prevent accidental use. Prefer standard AssertJ * {@code assertThat(context)...} calls instead. */ @@ -132,6 +132,7 @@ static , C extends ApplicationCont Assert.isTrue(type.isInterface(), "'type' must be an interface"); Assert.notNull(contextType, "'contextType' must not be null"); Assert.isTrue(contextType.isInterface(), "'contextType' must be an interface"); + Assert.notNull(contextSupplier, "'contextSupplier' must not be null"); Class[] interfaces = merge(new Class[] { type, contextType }, additionalContextInterfaces); return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, new AssertProviderApplicationContextInvocationHandler(contextType, contextSupplier)); diff --git a/core/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java index 9b11048bd608..f45941c26b40 100644 --- a/core/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/context/assertj/ApplicationContextAssertProviderTests.java @@ -20,9 +20,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; @@ -32,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.BDDMockito.then; +import static org.mockito.Mockito.mock; /** * Tests for {@link ApplicationContextAssertProvider} and @@ -39,12 +38,10 @@ * * @author Phillip Webb */ -@ExtendWith(MockitoExtension.class) class ApplicationContextAssertProviderTests { @Mock - @SuppressWarnings("NullAway.Init") - private ConfigurableApplicationContext mockContext; + private final ConfigurableApplicationContext mockContext = mock(); private RuntimeException startupFailure; @@ -70,15 +67,7 @@ void getWhenTypeIsNullShouldThrowException() { } @Test - @SuppressWarnings("NullAway") // Test null check void getWhenTypeIsClassShouldThrowException() { - assertThatIllegalArgumentException().isThrownBy( - () -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier)) - .withMessageContaining("'type' must not be null"); - } - - @Test - void getWhenContextTypeIsNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class, ApplicationContext.class, this.mockContextSupplier)) @@ -87,7 +76,7 @@ void getWhenContextTypeIsNullShouldThrowException() { @Test @SuppressWarnings("NullAway") // Test null check - void getWhenContextTypeIsClassShouldThrowException() { + void getWhenContextTypeIsNullShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, null, this.mockContextSupplier)) @@ -95,13 +84,22 @@ void getWhenContextTypeIsClassShouldThrowException() { } @Test - void getWhenSupplierIsNullShouldThrowException() { + void getWhenContextTypeIsClassShouldThrowException() { assertThatIllegalArgumentException() .isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, StaticApplicationContext.class, this.mockContextSupplier)) .withMessageContaining("'contextType' must be an interface"); } + @Test + @SuppressWarnings("NullAway") // Test null check + void getWhenSupplierIsNullShouldThrowException() { + assertThatIllegalArgumentException() + .isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, + ApplicationContext.class, null)) + .withMessageContaining("'contextSupplier' must not be null"); + } + @Test void getWhenContextStartsShouldReturnProxyThatCallsRealMethods() { ApplicationContextAssertProvider context = get(this.mockContextSupplier); diff --git a/core/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java b/core/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java index e6a7fbb997e1..88287de72d1c 100644 --- a/core/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java +++ b/core/spring-boot/src/test/java/org/springframework/boot/web/servlet/AbstractFilterRegistrationBeanTests.java @@ -234,7 +234,7 @@ private void doubleRegistration() throws ServletException { } @Test - void doesntFailIfDoubleRegistrationIsIgnored() { + void doesNotFailIfDoubleRegistrationIsIgnored() { assertThatCode(() -> { AbstractFilterRegistrationBean bean = createFilterRegistrationBean(); bean.setName("double-registration"); diff --git a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java index 37ff6bef3637..f1cc7ec2ba8e 100644 --- a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java +++ b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/remote/client/RemoteClientConfigurationTests.java @@ -92,7 +92,7 @@ void warnIfNotHttps(CapturedOutput output) { } @Test - void doesntWarnIfUsingHttps(CapturedOutput output) { + void doesNotWarnIfUsingHttps(CapturedOutput output) { configure("https://localhost", true); assertThat(output).doesNotContain("is insecure"); } diff --git a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java index ad081ee2b1e3..ec8f32f9faa8 100644 --- a/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java +++ b/module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java @@ -47,7 +47,7 @@ public void run() { } @Test - void doesntInterfereWithOtherExceptions() throws Exception { + void doesNotInterfereWithOtherExceptions() throws Exception { TestThread testThread = new TestThread() { @Override public void run() {