use of org.springframework.web.bind.support.WebRequestDataBinder in project spring-framework by spring-projects.
the class AbstractRequestAttributesArgumentResolverTests method resolveOptional.
@Test
public void resolveOptional() throws Exception {
WebDataBinder dataBinder = new WebRequestDataBinder(null);
dataBinder.setConversionService(new DefaultConversionService());
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(this.webRequest, null, "foo")).willReturn(dataBinder);
MethodParameter param = initMethodParameter(3);
Object actual = testResolveArgument(param, factory);
assertThat(actual).isNotNull();
assertThat(actual.getClass()).isEqualTo(Optional.class);
assertThat(((Optional<?>) actual).isPresent()).isFalse();
Foo foo = new Foo();
this.webRequest.setAttribute("foo", foo, getScope());
actual = testResolveArgument(param, factory);
assertThat(actual).isNotNull();
assertThat(actual.getClass()).isEqualTo(Optional.class);
assertThat(((Optional<?>) actual).isPresent()).isTrue();
assertThat(((Optional<?>) actual).get()).isSameAs(foo);
}
use of org.springframework.web.bind.support.WebRequestDataBinder in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingRequestParamEmptyValueNotRequired.
@Test
public void missingRequestParamEmptyValueNotRequired() throws Exception {
WebDataBinder binder = new WebRequestDataBinder(null);
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
request.addParameter("name", "");
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertThat(arg).isNull();
}
use of org.springframework.web.bind.support.WebRequestDataBinder in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method resovleArgumentViaDefaultConstructor.
@Test
public void resovleArgumentViaDefaultConstructor() throws Exception {
WebDataBinder dataBinder = new WebRequestDataBinder(null);
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(any(), notNull(), eq("attrName"))).willReturn(dataBinder);
this.processor.resolveArgument(this.paramNamedValidModelAttr, this.container, this.request, factory);
verify(factory).createBinder(any(), notNull(), eq("attrName"));
}
use of org.springframework.web.bind.support.WebRequestDataBinder in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method testGetAttributeFromModel.
private void testGetAttributeFromModel(String expectedAttrName, MethodParameter param) throws Exception {
Object target = new TestBean();
this.container.addAttribute(expectedAttrName, target);
WebDataBinder dataBinder = new WebRequestDataBinder(target);
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(this.request, target, expectedAttrName)).willReturn(dataBinder);
this.processor.resolveArgument(param, this.container, this.request, factory);
verify(factory).createBinder(this.request, target, expectedAttrName);
}
use of org.springframework.web.bind.support.WebRequestDataBinder in project spring-framework by spring-projects.
the class ModelAttributeMethodProcessorTests method resolveArgumentViaDefaultConstructor.
@Test
public void resolveArgumentViaDefaultConstructor() throws Exception {
WebDataBinder dataBinder = new WebRequestDataBinder(null);
WebDataBinderFactory factory = mock(WebDataBinderFactory.class);
given(factory.createBinder(any(), notNull(), eq("attrName"))).willReturn(dataBinder);
this.processor.resolveArgument(this.paramNamedValidModelAttr, this.container, this.request, factory);
verify(factory).createBinder(any(), notNull(), eq("attrName"));
}
Aggregations