PropertyConverter { public static Integer toInteger(Object value) throws ConversionException { Number n = toNumber(value, Integer.class); if (n instanceof Integer) { return (Integer) n; } else { return new Integer(n.intValue()); } } private  PropertyConverter(); static Boolean toBoolean(Object value); static Integer toInteger(Object value); static Long toLong(Object value); static BigInteger toBigInteger(Object value); static List<String> toList(Object value); static Set<String> toSet(Object value);  }
@Test public void testToInteger() { assertEquals(Integer.valueOf(1), toInteger("1")); assertEquals(Integer.valueOf(1), toInteger(1L)); assertEquals(Integer.valueOf(255), toInteger("0xFF")); assertEquals(Integer.valueOf(1), toInteger("0b1")); }
@Test public void testFailToInteger() { Throwable t = assertThrows(ConversionException.class, () -> toInteger(BAD_COMPARISON)); assertEquals(expectedMessage(BAD_COMPARISON, Integer.class), t.getMessage()); }