BooleanUtils { public static boolean valueToBoolean(int value) { if (TRUE == value) { return true; } else if (FALSE == value) { return false; } else { throw new RuntimeException("Boolean value error, must be 0 or 1"); } }  static boolean valueToBoolean(int value); static int booleanToValue(Boolean booleanValue); static final int TRUE; static final int FALSE; }
@Test public void testValueToBoolean() { assertEquals(1, BooleanUtils.booleanToValue(true)); assertEquals(0, BooleanUtils.booleanToValue(false)); }
@Test(expected = RuntimeException.class) public void shouldThrowIfValueIsNotZeroOrOne() { boolean ignored = BooleanUtils.valueToBoolean(123); }