type formatters

This commit is contained in:
Keith Donald
2009-07-20 14:26:29 +00:00
parent b2c723a76e
commit 3cd3cddbe0
7 changed files with 204 additions and 131 deletions

View File

@@ -97,32 +97,29 @@ public class GenericBinderTests {
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
}
/*
@Test
public void bindSingleValuePropertyFormatterParseException() {
BindingRulesBuilder builder = new BindingRulesBuilder(TestBean.class);
builder.bind("date").formatWith(new DateFormatter());
GenericBinder binder = new GenericBinder(bean, builder.getBindingRules());
GenericBinder binder = new GenericBinder(bean);
binder.bindingRule("date").formatWith(new DateFormatter());
BindingResults results = binder.bind(Collections.singletonMap("date", "bogus"));
assertEquals(1, results.size());
assertTrue(results.get(0).isFailure());
assertEquals("invalidFormat", results.get(0).getAlert().getCode());
assertEquals("typeMismatch", results.get(0).getAlert().getCode());
}
@Test
public void bindSingleValueWithFormatterRegistedByType() throws ParseException {
BindingRulesBuilder builder = new BindingRulesBuilder(TestBean.class);
builder.bind("date").formatWith(new DateFormatter());
GenericBinder binder = new GenericBinder(bean, builder.getBindingRules());
GenericBinder binder = new GenericBinder(bean);
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
formatterRegistry.add(Date.class, new DateFormatter());
binder.setFormatterRegistry(formatterRegistry);
binder.bind(Collections.singletonMap("date", "2009-06-01"));
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
}
/*
@Test
public void bindSingleValueWithAnnotationFormatterFactoryRegistered() throws ParseException {
binder.addBinding("currency");