Browse Source

Introduce Mono#justOrEmpty(T)

pull/1111/head
Stephane Maldini 9 years ago
parent
commit
fc1b2e96f7
  1. 3
      spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/RequestParamArgumentResolver.java
  2. 7
      spring-web-reactive/src/test/java/org/springframework/web/reactive/view/ViewResolverResultHandlerTests.java

3
spring-web-reactive/src/main/java/org/springframework/web/reactive/method/annotation/RequestParamArgumentResolver.java

@ -46,8 +46,7 @@ public class RequestParamArgumentResolver implements HandlerMethodArgumentResolv @@ -46,8 +46,7 @@ public class RequestParamArgumentResolver implements HandlerMethodArgumentResolv
RequestParam annotation = param.getParameterAnnotation(RequestParam.class);
String name = (annotation.value().length() != 0 ? annotation.value() : param.getParameterName());
UriComponents uriComponents = UriComponentsBuilder.fromUri(exchange.getRequest().getURI()).build();
String value = uriComponents.getQueryParams().getFirst(name);
return (value != null ? Mono.just(value) : Mono.empty());
return Mono.justOrEmpty(uriComponents.getQueryParams().getFirst(name));
}
}

7
spring-web-reactive/src/test/java/org/springframework/web/reactive/view/ViewResolverResultHandlerTests.java

@ -57,10 +57,7 @@ import org.springframework.web.server.session.DefaultWebSessionManager; @@ -57,10 +57,7 @@ import org.springframework.web.server.session.DefaultWebSessionManager;
import org.springframework.web.server.session.WebSessionManager;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
@ -226,7 +223,7 @@ public class ViewResolverResultHandlerTests { @@ -226,7 +223,7 @@ public class ViewResolverResultHandlerTests {
@Override
public Mono<View> resolveViewName(String viewName, Locale locale) {
View view = this.views.get(viewName);
return (view != null ? Mono.just(view) : Mono.empty());
return Mono.justOrEmpty(view);
}
}

Loading…
Cancel
Save