ParseUtils { public static boolean parseStringAsBoolean(String in) throws IndexParseFieldException { in = in.trim(); if (in.equalsIgnoreCase("T")) { return true; } else if (in.equalsIgnoreCase("TRUE")) { return true; } else if (in.equalsIgnoreCase("1")) { return true; } else if (in.equalsIgnoreCase("F")) { return false; } else if (in.equalsIgnoreCase("FALSE")) { return false; } else if (in.equalsIgnoreCase("0")) { return false; } throw new IndexParseFieldException(in); }  static ByteBuffer parseBase64StringAsByteBuffer(String in); static boolean parseStringAsBoolean(String in); static Date parseStringAsDate(String in); static double parseStringAsDouble(String in); static int parseStringAsInt(String in); static UUID parseStringAsUUID(String in); static Long parseStringAsLong(String in);  }
@Test public void testParseStringAsBoolean() throws Exception { System.out.println("parseStringAsBoolean"); boolean result = ParseUtils.parseStringAsBoolean("false"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("False"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("faLSe"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("FALSE"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("f"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("F"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("0"); assertEquals(false, result); result = ParseUtils.parseStringAsBoolean("true"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("True"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("tRUe"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("TRUE"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("t"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("T"); assertEquals(true, result); result = ParseUtils.parseStringAsBoolean("1"); assertEquals(true, result); boolean expectExceptionThrown = false; try { ParseUtils.parseStringAsBoolean(""); } catch (IndexParseFieldException e) { expectExceptionThrown = true; assertNull(e.getCause()); assertNotNull(e.getMessage()); } assertTrue(expectExceptionThrown); expectExceptionThrown = false; try { ParseUtils.parseStringAsBoolean("blah"); } catch (IndexParseFieldException e) { expectExceptionThrown = true; assertNull(e.getCause()); assertNotNull(e.getMessage()); assertTrue(e.getMessage().contains("blah")); assertEquals(e.getFieldValue(), "blah"); } assertTrue(expectExceptionThrown); }