From 8dd64602e89d681bf9e35dfc637d2efdf8515d54 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:11:42 +0200 Subject: [PATCH] Avoid warnings with AssertJ APIs --- .../annotation/ApiVersionMethodArgumentResolverTests.java | 5 +++-- .../annotation/ApiVersionMethodArgumentResolverTests.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ApiVersionMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ApiVersionMethodArgumentResolverTests.java index 354025c80d2..a1044162f5c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ApiVersionMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ApiVersionMethodArgumentResolverTests.java @@ -32,6 +32,7 @@ import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRe import org.springframework.web.testfixture.server.MockServerWebExchange; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL; /** * Tests for {@link ApiVersionMethodArgumentResolver}. @@ -94,13 +95,13 @@ class ApiVersionMethodArgumentResolverTests { this.exchange.getAttributes().put(HandlerMapping.API_VERSION_ATTRIBUTE, version); Object actual = this.resolver.resolveArgumentValue(this.optionalParam, new BindingContext(), exchange); - assertThat(((Optional) actual)).hasValue(version); + assertThat(actual).asInstanceOf(OPTIONAL).hasValue(version); } @Test void resolveOptionalArgumentWhenEmpty() { Object actual = this.resolver.resolveArgumentValue(this.optionalParam, new BindingContext(), exchange); - assertThat(((Optional) actual)).isEmpty(); + assertThat(actual).asInstanceOf(OPTIONAL).isEmpty(); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ApiVersionMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ApiVersionMethodArgumentResolverTests.java index 7eeba187740..18663afee2b 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ApiVersionMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ApiVersionMethodArgumentResolverTests.java @@ -32,6 +32,7 @@ import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.OPTIONAL; /** * Test fixture with {@link ApiVersionMethodArgumentResolver}. @@ -102,13 +103,13 @@ class ApiVersionMethodArgumentResolverTests { this.servletRequest.setAttribute(HandlerMapping.API_VERSION_ATTRIBUTE, version); Object actual = this.resolver.resolveArgument(this.optionalParam, this.mav, this.webRequest, null); - assertThat(((Optional) actual)).hasValue(version); + assertThat(actual).asInstanceOf(OPTIONAL).hasValue(version); } @Test void resolveOptionalArgumentWhenEmpty() throws Exception { Object actual = this.resolver.resolveArgument(this.optionalParam, this.mav, this.webRequest, null); - assertThat(((Optional) actual)).isEmpty(); + assertThat(actual).asInstanceOf(OPTIONAL).isEmpty(); }