use of org.springframework.web.bind.support.WebDataBinderFactory 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.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderWithAttrNameNoMatch.
@Test
public void createBinderWithAttrNameNoMatch() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, "invalidName");
assertThat(dataBinder.getDisallowedFields()).isNull();
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderNullAttrName.
@Test
public void createBinderNullAttrName() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderWithAttributeName", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
assertThat(dataBinder.getDisallowedFields()).isNull();
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method createBinderWithGlobalInitialization.
@Test
public void createBinderWithGlobalInitialization() throws Exception {
ConversionService conversionService = new DefaultFormattingConversionService();
bindingInitializer.setConversionService(conversionService);
WebDataBinderFactory factory = createFactory("initBinder", WebDataBinder.class);
WebDataBinder dataBinder = factory.createBinder(this.webRequest, null, null);
assertThat(dataBinder.getConversionService()).isSameAs(conversionService);
}
use of org.springframework.web.bind.support.WebDataBinderFactory in project spring-framework by spring-projects.
the class InitBinderDataBinderFactoryTests method returnValueNotExpected.
@Test
public void returnValueNotExpected() throws Exception {
WebDataBinderFactory factory = createFactory("initBinderReturnValue", WebDataBinder.class);
assertThatIllegalStateException().isThrownBy(() -> factory.createBinder(this.webRequest, null, "invalidName"));
}
Aggregations