TypeDecoder { public static ValueHolder decode(Type<?> type, String text) { try { return type.decode(text != null ? text.trim() : null); } catch (RuntimeException exception) { throw new TypeDecodingException(exception, text, type); } } private  TypeDecoder(); static ValueHolder decode(Type<?> type, String text); static ValueHolder convert(Type<?> type, Object obj); static ValueHolder[] convert(Type<?> type, Object[] array); static ValueHolder[] convert(Type<?> type, Collection<?> coll);  }
@Test public void testDecode() { Object[][] testCases = { {"0", new IntegerHolder(0L)}, {" -99", new IntegerHolder(-99L)}, {null, new IntegerHolder(null)}, {"\t \n", new IntegerHolder(null)} }; for (Object[] testCase : testCases) { String text = (String) testCase[0]; ValueHolder expectedHolder = (ValueHolder) testCase[1]; ValueHolder holder = TypeDecoder.decode(type, text); assertEquals(expectedHolder.getValue(), holder.getValue()); } }
@Test public void testDecode__illegalArgument() { String[] illegals = {"1.1", "9aa", "."}; for (String text : illegals) { try { TypeDecoder.decode(type, text); fail(); } catch (TypeDecodingException e) { } } }