use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingOptionalParamList.
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamList() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, List.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveOptionalMultipartFile.
@Test
public void resolveOptionalMultipartFile() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes());
request.addFile(expected);
webRequest = new ServletWebRequest(request);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
boolean condition = result instanceof Optional;
assertThat(condition).isTrue();
assertThat(((Optional<?>) result).get()).as("Invalid result").isEqualTo(expected);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method resolveOptionalParamValue.
@Test
@SuppressWarnings("rawtypes")
public void resolveOptionalParamValue() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
request.addParameter("name", "123");
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).get()).isEqualTo(123);
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingOptionalParamArray.
@Test
@SuppressWarnings("rawtypes")
public void missingOptionalParamArray() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer[].class);
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result).isEqualTo(Optional.empty());
result = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(result.getClass()).isEqualTo(Optional.class);
assertThat(((Optional) result).isPresent()).isFalse();
}
use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method optionalMultipartFileWithoutMultipartRequest.
@Test
public void optionalMultipartFileWithoutMultipartRequest() throws Exception {
ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
initializer.setConversionService(new DefaultConversionService());
WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
Object actual = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(actual).isEqualTo(Optional.empty());
}
Aggregations