From de3483c5aa5da6b08783aef1f558cdb27382131b Mon Sep 17 00:00:00 2001 From: albonidrizi Date: Fri, 12 Dec 2025 15:27:38 +0100 Subject: [PATCH] Resolve TODO: Add test for expression resolution with ServerWebExchange Add resolveWithServerWebExchange() test method to verify that @Value expression resolution works correctly when a ServerWebExchange is provided. The test creates a custom MockServerWebExchange with request headers and attributes, then confirms that expressions are properly resolved in the presence of the exchange context. This resolves the TODO at line 96 and ensures the resolver functions correctly in reactive WebFlux contexts with ServerWebExchange instances. Signed-off-by: albonidrizi --- ...ssionValueMethodArgumentResolverTests.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java index 61f3bddf22f..0b7632945ee 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ExpressionValueMethodArgumentResolverTests.java @@ -48,6 +48,7 @@ class ExpressionValueMethodArgumentResolverTests { private MethodParameter paramSystemProperty; private MethodParameter paramNotSupported; private MethodParameter paramAlsoNotSupported; + private MethodParameter paramWithExchange; @BeforeEach @@ -61,6 +62,7 @@ class ExpressionValueMethodArgumentResolverTests { this.paramSystemProperty = new MethodParameter(method, 0); this.paramNotSupported = new MethodParameter(method, 1); this.paramAlsoNotSupported = new MethodParameter(method, 2); + this.paramWithExchange = new MethodParameter(method, 3); } @@ -93,14 +95,36 @@ class ExpressionValueMethodArgumentResolverTests { } - // TODO: test with expression for ServerWebExchange + @Test + void resolveWithServerWebExchange() { + System.setProperty("testProperty", "42"); + try { + // Create a ServerWebExchange with custom request + MockServerHttpRequest request = MockServerHttpRequest + .get("/test-path") + .header("X-Test-Header", "test-value") + .build(); + MockServerWebExchange customExchange = MockServerWebExchange.from(request); + customExchange.getAttributes().put("testAttribute", "attributeValue"); + + Mono mono = this.resolver.resolveArgument( + this.paramWithExchange, new BindingContext(), customExchange); + + Object value = mono.block(); + assertThat(value).isEqualTo(42); + } + finally { + System.clearProperty("testProperty"); + } + } @SuppressWarnings("unused") public void params( @Value("#{systemProperties.systemProperty}") int param1, String notSupported, - @Value("#{systemProperties.foo}") Mono alsoNotSupported) { + @Value("#{systemProperties.foo}") Mono alsoNotSupported, + @Value("#{systemProperties.testProperty}") int param4) { } }