From 9d5c7a15f30f44a2b825b752e5f8a2399eb29873 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Thu, 16 Oct 2025 09:04:39 +0200 Subject: [PATCH] Add nullability annotations to tests in module/spring-boot-webmvc-test See gh-47263 --- module/spring-boot-webmvc-test/build.gradle | 5 +++++ .../SpringBootMockMvcBuilderCustomizerTests.java | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/module/spring-boot-webmvc-test/build.gradle b/module/spring-boot-webmvc-test/build.gradle index bdde6299137..d27c928aef7 100644 --- a/module/spring-boot-webmvc-test/build.gradle +++ b/module/spring-boot-webmvc-test/build.gradle @@ -56,3 +56,8 @@ dependencies { tasks.named("test") { exclude("**/WebMvcTestPrintDefaultIntegrationTests\$*") } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} + diff --git a/module/spring-boot-webmvc-test/src/test/java/org/springframework/boot/webmvc/test/autoconfigure/SpringBootMockMvcBuilderCustomizerTests.java b/module/spring-boot-webmvc-test/src/test/java/org/springframework/boot/webmvc/test/autoconfigure/SpringBootMockMvcBuilderCustomizerTests.java index 20dbcd6222d..382b64695b5 100644 --- a/module/spring-boot-webmvc-test/src/test/java/org/springframework/boot/webmvc/test/autoconfigure/SpringBootMockMvcBuilderCustomizerTests.java +++ b/module/spring-boot-webmvc-test/src/test/java/org/springframework/boot/webmvc/test/autoconfigure/SpringBootMockMvcBuilderCustomizerTests.java @@ -70,6 +70,7 @@ class SpringBootMockMvcBuilderCustomizerTests { FilterRegistrationBean registrationBean = (FilterRegistrationBean) context.getBean("otherTestFilter"); TestFilter testFilter = context.getBean("testFilter", TestFilter.class); OtherTestFilter otherTestFilter = (OtherTestFilter) registrationBean.getFilter(); + assertThat(otherTestFilter).isNotNull(); assertThat(builder).extracting("filters", as(InstanceOfAssertFactories.LIST)) .extracting("delegate", "dispatcherTypes") .containsExactlyInAnyOrder(tuple(testFilter, EnumSet.of(DispatcherType.REQUEST)), @@ -96,6 +97,7 @@ class SpringBootMockMvcBuilderCustomizerTests { Thread thread = new Thread(() -> { for (int j = 0; j < 1000; j++) { DeferredLinesWriter writer = DeferredLinesWriter.get(context); + assertThat(writer).isNotNull(); writer.write(Arrays.asList("1", "2", "3", "4", "5")); writer.writeDeferredResult(); writer.clear(); @@ -162,9 +164,10 @@ class SpringBootMockMvcBuilderCustomizerTests { static class TestFilter implements Filter { + @SuppressWarnings("NullAway.Init") private String filterName; - private Map initParams = new HashMap<>(); + private final Map initParams = new HashMap<>(); @Override public void init(FilterConfig filterConfig) { @@ -187,9 +190,10 @@ class SpringBootMockMvcBuilderCustomizerTests { static class OtherTestFilter implements Filter { + @SuppressWarnings("NullAway.Init") private String filterName; - private Map initParams = new HashMap<>(); + private final Map initParams = new HashMap<>(); @Override public void init(FilterConfig filterConfig) {