Search in sources :

Example 36 with WebDataBinderFactory

use of org.springframework.web.bind.support.WebDataBinderFactory 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());
}
Also used : ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) RequestParam(org.springframework.web.bind.annotation.RequestParam) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) MethodParameter(org.springframework.core.MethodParameter) DefaultDataBinderFactory(org.springframework.web.bind.support.DefaultDataBinderFactory) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Test(org.junit.jupiter.api.Test)

Aggregations

WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)36 Test (org.junit.jupiter.api.Test)32 WebDataBinder (org.springframework.web.bind.WebDataBinder)16 MethodParameter (org.springframework.core.MethodParameter)12 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)12 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)12 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)11 RequestParam (org.springframework.web.bind.annotation.RequestParam)10 Optional (java.util.Optional)8 WebRequestDataBinder (org.springframework.web.bind.support.WebRequestDataBinder)7 TestBean (org.springframework.beans.testfixture.beans.TestBean)6 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)5 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 StringTrimmerEditor (org.springframework.beans.propertyeditors.StringTrimmerEditor)2 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)2 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1