NumberType implements Type<NumberHolder> { @Override public NumberHolder decode(String text) { BigDecimal value = EngineUtil.hasText(text) ? parse(text) : null; return new NumberHolder(value); }  @Override String encode(NumberHolder value); @Override NumberHolder decode(String text); @Override NumberHolder convert(Object obj); @Override NumberHolder[] newArray(int size); static final String TYPE_NAME; }
@Test public void testDecode() { Object[][] testCases = { {"-100", num2(new BigDecimal("-100"))}, {"-100.00", num2(new BigDecimal("-100.00"))}, {"0.0", num2(new BigDecimal("0.0"))}, {".0", num2(new BigDecimal("0.0"))}, {" .00 ", num2(new BigDecimal("0.00"))}, {null, new NumberHolder(null)}, {" ", new NumberHolder(null)}, {"", new NumberHolder(null)}, {"1e3", num2(new BigDecimal("1e3"))}, {"1.2e2", num2(new BigDecimal("1.2E2"))}, {"1,23", num2(new BigDecimal("1.23"))}, {"1 234", num2(new BigDecimal("1234"))} }; for (Object[] testCase : testCases) { String text = (String) testCase[0]; NumberHolder expectedHolder = (NumberHolder) testCase[1]; assertEquals(expectedHolder, type.decode(text)); assertEquals(expectedHolder.getBigDecimal(), type.decode(text).getBigDecimal()); } }
@Test public void testDecode__illegalArgument() { String[] illegals = {"aa", "1b"}; for (String text : illegals) { try { type.decode(text); fail(); } catch (NumberFormatException nfe) { } } }