From b68f76c86e356044b6f88884172d7f025061c3a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Thu, 4 Apr 2024 14:40:31 +0200 Subject: [PATCH] Polish See gh-32502 --- .../result/method/InvocableHandlerMethod.java | 1 + .../annotation/ControllerMethodResolver.java | 16 +++++++--------- .../method/InvocableHandlerMethodTests.java | 2 +- .../method/annotation/ControllerAdviceTests.java | 4 +++- .../method/annotation/ModelInitializerTests.java | 3 +-- .../RequestMappingIntegrationTests.java | 8 +++----- .../annotation/ModelInitializerKotlinTests.kt | 2 +- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index e9d7a33b01..d863e74ecf 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -247,6 +247,7 @@ public class InvocableHandlerMethod extends HandlerMethod { if (ObjectUtils.isEmpty(parameters)) { return EMPTY_ARGS; } + List> argMonos = new ArrayList<>(parameters.length); for (MethodParameter parameter : parameters) { parameter.initParameterNameDiscovery(this.parameterNameDiscoverer); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java index 04158378f8..7fda733d8e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -104,6 +104,12 @@ class ControllerMethodResolver { private final ReactiveAdapterRegistry reactiveAdapterRegistry; + @Nullable + private final Scheduler invocationScheduler; + + @Nullable + private final Predicate blockingMethodPredicate; + @Nullable private final MethodValidator methodValidator; @@ -122,12 +128,6 @@ class ControllerMethodResolver { private final Map, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap<>(64); - @Nullable - private final Scheduler invocationScheduler; - - @Nullable - private final Predicate blockingMethodPredicate; - ControllerMethodResolver( ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry adapterRegistry, @@ -323,9 +323,7 @@ class ControllerMethodResolver { invocable.setArgumentResolvers(this.requestMappingResolvers); invocable.setReactiveAdapterRegistry(this.reactiveAdapterRegistry); invocable.setMethodValidator(this.methodValidator); - //getSchedulerFor returns null if not applicable, which is ok here invocable.setInvocationScheduler(getSchedulerFor(handlerMethod)); - return invocable; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java index cf51816dd2..c906010880 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java @@ -105,7 +105,7 @@ class InvocableHandlerMethodTests { @Test void resolveNoArgsOnSchedulerThread() { - Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.noArgsThread()).method(); + Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::noArgsThread).method(); Mono mono = invokeOnScheduler(Schedulers.newSingle("good"), new TestController(), method); assertHandlerResultValue(mono, "on thread: good-", false); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerAdviceTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerAdviceTests.java index 1163a020b8..0cbd20e909 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerAdviceTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerAdviceTests.java @@ -217,7 +217,9 @@ class ControllerAdviceTests { Method method = controller.getClass().getMethod(methodName, parameterTypes); HandlerMethod handlerMethod = new HandlerMethod(controller, method); - return adapter.handle(exchange, handlerMethod).block(timeout); + HandlerResult handlerResult = adapter.handle(exchange, handlerMethod).block(timeout); + assertThat(handlerResult).isNotNull(); + return handlerResult; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java index 675079f9cf..6f55870375 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java @@ -80,8 +80,7 @@ class ModelInitializerTests { ControllerMethodResolver methodResolver = new ControllerMethodResolver( resolverConfigurer, adapterRegistry, new StaticApplicationContext(), - Collections.emptyList(), null, - null, null); + Collections.emptyList(), null, null, null); this.modelInitializer = new ModelInitializer(methodResolver, adapterRegistry); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java index b1a9465676..34d8a2cd6d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -78,10 +78,8 @@ class RequestMappingIntegrationTests extends AbstractRequestMappingIntegrationTe url += "/"; assertThat(getRestTemplate().getForObject(url, String.class)).isEqualTo("root"); - assertThat(getApplicationContext().getBean(TestExecutor.class).invocationCount.get()) - .as("executor").isEqualTo(4); - assertThat(getApplicationContext().getBean(TestPredicate.class).invocationCount.get()) - .as("predicate").isEqualTo(4); + assertThat(getApplicationContext().getBean(TestExecutor.class).invocationCount.get()).isEqualTo(4); + assertThat(getApplicationContext().getBean(TestPredicate.class).invocationCount.get()).isEqualTo(4); } @ParameterizedHttpServerTest diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/result/method/annotation/ModelInitializerKotlinTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/result/method/annotation/ModelInitializerKotlinTests.kt index 5de51c2e1d..9ece488448 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/result/method/annotation/ModelInitializerKotlinTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/result/method/annotation/ModelInitializerKotlinTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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.