PropertyConverter { public static Boolean toBoolean(Object value) throws ConversionException { if (value == null) { return false; } if (value instanceof Boolean) { return (Boolean) value; } else if (value instanceof String) { if ("1".equalsIgnoreCase((String) value) || "y".equalsIgnoreCase((String) value)) { return true; } return BooleanUtils.toBoolean((String) value); } else { String msg = formatErrorMessage(value, Boolean.class); log.warn(msg); throw new ConversionException(msg); } } 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 testToBoolean() { assertTrue(toBoolean("true")); assertTrue(toBoolean("yes")); assertTrue(toBoolean("on")); assertFalse(toBoolean("false")); assertFalse(toBoolean("no")); assertFalse(toBoolean("off")); assertTrue(toBoolean("1")); assertTrue(toBoolean("y")); assertFalse(toBoolean("n")); assertFalse(toBoolean(null)); }
@Test public void testFailToBoolean() { Throwable t = assertThrows(ConversionException.class, () -> toBoolean(BAD_COMPARISON)); assertEquals(expectedMessage(BAD_COMPARISON, Boolean.class), t.getMessage()); }