IntegerType implements Type<IntegerHolder> { @Override public IntegerHolder decode(String text) { Long value = EngineUtil.hasText(text) ? Long.valueOf(text.trim()) : null; return new IntegerHolder(value); }  @Override String encode(IntegerHolder value); @Override IntegerHolder decode(String text); @Override IntegerHolder convert(Object obj); @Override IntegerHolder[] newArray(int size); static final String TYPE_NAME; }
@Test public void testDecode() { Object[][] testCases = { {"0", 0L}, {"-99", -99L}, {"2147483648", 2147483648L}, {null, null}, {"", null}, {"\t \n", null} }; for (Object[] testCase : testCases) { String text = (String) testCase[0]; Long expectedValue = (Long) testCase[1]; IntegerHolder holder = type.decode(text); assertEquals(expectedValue, holder.getValue()); } }
@Test public void testDecode__illegalArgument() { String[] illegals = {"1.1", "9aa"}; for (String text : illegals) { try { type.decode(text); fail(); } catch (NumberFormatException nfe) { } } }