Search in sources :

Example 6 with NumberTestBean

use of org.springframework.tests.sample.beans.NumberTestBean in project spring-framework by spring-projects.

the class CustomEditorTests method testCustomNumberEditorWithFrenchBigDecimal.

@Test
public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
    NumberTestBean tb = new NumberTestBean();
    BeanWrapper bw = new BeanWrapperImpl(tb);
    bw.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, nf, true));
    bw.setPropertyValue("bigDecimal", "1000");
    assertEquals(1000.0f, tb.getBigDecimal().floatValue(), 0f);
    bw.setPropertyValue("bigDecimal", "1000,5");
    assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f);
    bw.setPropertyValue("bigDecimal", "1 000,5");
    assertEquals(1000.5f, tb.getBigDecimal().floatValue(), 0f);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)6 BigDecimal (java.math.BigDecimal)5 BigInteger (java.math.BigInteger)4 BeanWrapper (org.springframework.beans.BeanWrapper)4 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)4 NumberFormat (java.text.NumberFormat)3 BeansException (org.springframework.beans.BeansException)1