use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testPlaceholdersBinding.
@Test
public void testPlaceholdersBinding() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getName()).isEqualTo("bar");
}
use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testPlaceholdersBindingWithError.
@Test
public void testPlaceholdersBindingWithError() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new MapPropertySource("another", Collections.<String, Object>singletonMap("something", "${nonexistent}")));
binder.bind(new PropertySourcesPropertyValues(this.propertySources));
assertThat(target.getName()).isEqualTo("bar");
}
use of org.springframework.validation.DataBinder in project spring-boot by spring-projects.
the class PropertySourcesPropertyValuesTests method testPlaceholdersBindingNonEnumerable.
@Test
public void testPlaceholdersBindingNonEnumerable() {
FooBean target = new FooBean();
DataBinder binder = new DataBinder(target);
binder.bind(new PropertySourcesPropertyValues(this.propertySources, (Collection<String>) null, Collections.singleton("foo")));
assertThat(target.getFoo()).isEqualTo("bar");
}
use of org.springframework.validation.DataBinder in project spring-framework by spring-projects.
the class MoneyFormattingTests method testAmountWithNumberFormat1.
@Test
public void testAmountWithNumberFormat1() {
FormattedMoneyHolder1 bean = new FormattedMoneyHolder1();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(conversionService);
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("amount", "$10.50");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
LocaleContextHolder.setLocale(Locale.CANADA);
binder.bind(propertyValues);
LocaleContextHolder.setLocale(Locale.US);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
assertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode());
}
use of org.springframework.validation.DataBinder in project spring-framework by spring-projects.
the class MoneyFormattingTests method testAmountWithNumberFormat2.
@Test
public void testAmountWithNumberFormat2() {
FormattedMoneyHolder2 bean = new FormattedMoneyHolder2();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(conversionService);
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("amount", "10.50");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("10.5", binder.getBindingResult().getFieldValue("amount"));
assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}
Aggregations