diff --git a/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java index 4284a577198..4443f6a554d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2025 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. @@ -106,7 +106,7 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * {@link #WebMergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, String, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} */ @Deprecated(since = "6.1") - public WebMergedContextConfiguration(Class testClass, String @Nullable [] locations, @Nullable Class[] classes, + public WebMergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, String resourceBasePath, ContextLoader contextLoader, diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 5c004fb39ca..71efb61dfb1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -547,20 +547,21 @@ class DefaultWebTestClient implements WebTestClient { } @Override - public T isEqualTo(B expected) { + public T isEqualTo(@Nullable B expected) { this.result.assertWithDiagnostics(() -> AssertionErrors.assertEquals("Response body", expected, this.result.getResponseBody())); return self(); } @Override - public T value(Matcher matcher) { + public T value(Matcher matcher) { this.result.assertWithDiagnostics(() -> MatcherAssert.assertThat(this.result.getResponseBody(), matcher)); return self(); } @Override - public T value(Function bodyMapper, Matcher matcher) { + @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1129 + public T value(Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher) { this.result.assertWithDiagnostics(() -> { B body = this.result.getResponseBody(); MatcherAssert.assertThat(bodyMapper.apply(body), matcher); @@ -569,7 +570,8 @@ class DefaultWebTestClient implements WebTestClient { } @Override - public T value(Consumer consumer) { + @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1129 + public T value(Consumer<@Nullable B> consumer) { this.result.assertWithDiagnostics(() -> consumer.accept(this.result.getResponseBody())); return self(); } @@ -592,7 +594,7 @@ class DefaultWebTestClient implements WebTestClient { } - private static class DefaultListBodySpec extends DefaultBodySpec, ListBodySpec> + private static class DefaultListBodySpec extends DefaultBodySpec, ListBodySpec> implements ListBodySpec { DefaultListBodySpec(EntityExchangeResult> result) { @@ -601,7 +603,7 @@ class DefaultWebTestClient implements WebTestClient { @Override public ListBodySpec hasSize(int size) { - List actual = getResult().getResponseBody(); + List<@Nullable E> actual = getResult().getResponseBody(); String message = "Response body does not contain " + size + " elements"; getResult().assertWithDiagnostics(() -> AssertionErrors.assertEquals(message, size, (actual != null ? actual.size() : 0))); @@ -610,9 +612,9 @@ class DefaultWebTestClient implements WebTestClient { @Override @SuppressWarnings("unchecked") - public ListBodySpec contains(E... elements) { + public ListBodySpec contains(@Nullable E... elements) { List expected = Arrays.asList(elements); - List actual = getResult().getResponseBody(); + List<@Nullable E> actual = getResult().getResponseBody(); String message = "Response body does not contain " + expected; getResult().assertWithDiagnostics(() -> AssertionErrors.assertTrue(message, (actual != null && actual.containsAll(expected)))); @@ -621,9 +623,9 @@ class DefaultWebTestClient implements WebTestClient { @Override @SuppressWarnings("unchecked") - public ListBodySpec doesNotContain(E... elements) { + public ListBodySpec doesNotContain(@Nullable E... elements) { List expected = Arrays.asList(elements); - List actual = getResult().getResponseBody(); + List<@Nullable E> actual = getResult().getResponseBody(); String message = "Response body should not have contained " + expected; getResult().assertWithDiagnostics(() -> AssertionErrors.assertTrue(message, (actual == null || !actual.containsAll(expected)))); @@ -631,7 +633,7 @@ class DefaultWebTestClient implements WebTestClient { } @Override - public EntityExchangeResult> returnResult() { + public EntityExchangeResult> returnResult() { return getResult(); } } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 21852defea4..921cf49dae9 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -918,26 +918,26 @@ public interface WebTestClient { /** * Assert the extracted body is equal to the given value. */ - T isEqualTo(B expected); + T isEqualTo(@Nullable B expected); /** * Assert the extracted body with a {@link Matcher}. * @since 5.1 */ - T value(Matcher matcher); + T value(Matcher matcher); /** * Transform the extracted the body with a function, for example, extracting a * property, and assert the mapped value with a {@link Matcher}. * @since 5.1 */ - T value(Function bodyMapper, Matcher matcher); + T value(Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher); /** * Assert the extracted body with a {@link Consumer}. * @since 5.1 */ - T value(Consumer consumer); + T value(Consumer<@Nullable B> consumer); /** * Assert the exchange result with the given {@link Consumer}. @@ -957,7 +957,7 @@ public interface WebTestClient { * * @param the body list element type */ - interface ListBodySpec extends BodySpec, ListBodySpec> { + interface ListBodySpec extends BodySpec, ListBodySpec> { /** * Assert the extracted list of values is of the given size. @@ -970,14 +970,14 @@ public interface WebTestClient { * @param elements the elements to check */ @SuppressWarnings("unchecked") - ListBodySpec contains(E... elements); + ListBodySpec contains(@Nullable E... elements); /** * Assert the extracted list of values doesn't contain the given elements. * @param elements the elements to check */ @SuppressWarnings("unchecked") - ListBodySpec doesNotContain(E... elements); + ListBodySpec doesNotContain(@Nullable E... elements); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java index 2204277e2de..a5af570c667 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -58,7 +58,7 @@ final class MockMvcFilterDecorator implements Filter { private final Filter delegate; - private final @Nullable Function filterConfigInitializer; + private final @Nullable Function<@Nullable ServletContext, FilterConfig> filterConfigInitializer; private final @Nullable EnumSet dispatcherTypes; @@ -103,7 +103,7 @@ final class MockMvcFilterDecorator implements Filter { this.hasPatterns = initPatterns(urlPatterns); } - private static Function getFilterConfigInitializer( + private static Function<@Nullable ServletContext, FilterConfig> getFilterConfigInitializer( Filter delegate, @Nullable String filterName, @Nullable Map initParams) { String className = delegate.getClass().getName();