use of cn.taketoday.format.support.DefaultFormattingConversionService in project today-infrastructure by TAKETODAY.
the class DataBinderTests method conversionWithInappropriateStringEditor.
@Test
void conversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
NameBean bean = new NameBean("Fred");
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
conversionService.addConverter(new NameBeanConverter());
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
use of cn.taketoday.format.support.DefaultFormattingConversionService in project today-framework by TAKETODAY.
the class DataBinderTests method conversionWithInappropriateStringEditor.
@Test
void conversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
NameBean bean = new NameBean("Fred");
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
conversionService.addConverter(new NameBeanConverter());
assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
use of cn.taketoday.format.support.DefaultFormattingConversionService in project today-framework by TAKETODAY.
the class RequestHeaderMethodArgumentResolverTests method dateConversion.
@Test
@SuppressWarnings("deprecation")
void dateConversion() throws Throwable {
String rfc1123val = "Thu, 21 Apr 2016 17:11:08 +0100";
servletRequest.addHeader("name", rfc1123val);
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
webRequest.setBindingContext(new BindingContext(bindingInitializer));
Object result = resolver.resolveArgument(webRequest, paramDate);
assertThat(result).isEqualTo(new Date(rfc1123val));
}
use of cn.taketoday.format.support.DefaultFormattingConversionService in project today-framework by TAKETODAY.
the class RequestHeaderMethodArgumentResolverTests method uuidConversionWithInvalidValue.
@Test
void uuidConversionWithInvalidValue() throws Throwable {
servletRequest.addHeader("name", "bogus-uuid");
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
webRequest.setBindingContext(new BindingContext(bindingInitializer));
assertThatExceptionOfType(MethodArgumentTypeMismatchException.class).isThrownBy(() -> resolver.resolveArgument(webRequest, paramUuid));
}
use of cn.taketoday.format.support.DefaultFormattingConversionService in project today-framework by TAKETODAY.
the class RequestHeaderMethodArgumentResolverTests method uuidConversionWithValidValue.
@Test
void uuidConversionWithValidValue() throws Throwable {
UUID uuid = UUID.randomUUID();
servletRequest.addHeader("name", uuid.toString());
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
webRequest.setBindingContext(new BindingContext(bindingInitializer));
Object result = resolver.resolveArgument(webRequest, paramUuid);
assertThat(result).isEqualTo(uuid);
}
Aggregations