ConversionHelper { public static final boolean getBoolean(final String strToParse, final boolean defaultValue) { if(strToParse == null) { return defaultValue; } try { return Boolean.parseBoolean(strToParse); } catch (Exception ex) { return defaultValue; } }  static String firstNonNull(final String ... strings); static int count(final String string, final String substring); static String decapitalize(String param, boolean allCapsStringToLowercase); static String decapitalize(final String param); static boolean isOnlyUpperCase(final String param); static final String getString(final String str, final String defaultValue); static final long getLong(final String strToParse, final long defaultValue); static final int getInt(final String strToParse, final int defaultValue); static final double getDouble(final String strToParse, final double defaultValue); static final boolean getBoolean(final String strToParse, final boolean defaultValue); static final boolean getOnOffBoolean(final String strToParse, final boolean defaultValue); static final List<String> getStringList(final List<String> idList); static final List<Integer> getIntList(final List<String> idList); static Set<T> asSet(final T... array);  }
@Test public void testGetBoolean() { String test = "true"; boolean result = ConversionHelper.getBoolean(test, false); assertTrue("Should get true", result); test = "True"; result = ConversionHelper.getBoolean(test, false); assertTrue("Should get true", result); test = "test"; result = ConversionHelper.getBoolean(test, false); assertTrue("Should get false", !result); result = ConversionHelper.getBoolean(null, true); assertTrue("Null should yield default value 'true'", result); result = ConversionHelper.getBoolean(null, false); assertTrue("Null should yield default value 'false'", !result); }