protected void tearDown() throws Exception {
Locale.setDefault(defaultLocale);
}
public void testFormat() {
MockContext mockContext = MockContext.initContext(Locale.US);
MockRequest req = mockContext.getMockRequest();
Number decNum = new Float(2.56f);
NumberField engF = new NumberField("en");
assertNull(engF.getPattern());
engF.setPattern("#.00");
assertEquals("#.00", engF.getPattern());
engF.setPattern(null);
assertNull(engF.getPattern());
engF.setValue("some Text");
assertEquals("some Text", engF.getValue());
assertNull(engF.getNumber());
engF.setValue("12.456,5656");
assertEquals("12.456,5656", engF.getValue());
assertEquals(new Double(12.456), engF.getNumber());
engF.setNumber(decNum);
assertEquals("2.56", engF.getValue());
assertEquals(2.56d, engF.getNumber().doubleValue(),0);
engF.setValue("123.6");
assertEquals(123.6d, engF.getNumber().doubleValue(),0);
assertEquals(engF.getNumber(), engF.getValueObject());
engF.setPattern("0");
engF.setNumber(new Float(123.6f));
assertEquals("124", engF.getValue());
assertEquals(124, engF.getNumber().intValue());
engF.setValue("123.6");
assertEquals("123.6", engF.getValue());
assertEquals(123.6f, engF.getNumber().floatValue(),0);
engF.setPattern("0.00");
engF.setNumber(new Float(123.6f));
assertEquals("123.60", engF.getValue());
assertEquals(123.6f, engF.getNumber().floatValue(),0);
engF.setValue("12.223");
assertEquals(12.223f, engF.getNumber().floatValue(),0);
//keeps the pattern
engF.setNumberFormat(NumberFormat.getInstance(Locale.GERMAN));
engF.setNumber(decNum);
assertEquals("2,56", engF.getValue());
engF.setValue("3456,134");
assertEquals(3456.134f, engF.getNumber().floatValue(),0);
mockContext = MockContext.initContext(Locale.GERMANY);
req = mockContext.getMockRequest();
NumberField germanF = new NumberField("de");
germanF.setNumber(decNum);
assertEquals("2,56", germanF.getValue());