@Test public void toBoolean_valueIsNotTrueOrFalse() throws JspException { try { JspTagUtils.toBoolean("on", true, "field1"); fail("should be occurred JspTagException."); } catch (JspTagException e) { assertThat(e.getMessage(), is( "The value of field1 must be either true or false.")); } try { JspTagUtils.toBoolean("off", false, "field2"); fail("should be occurred JspTagException."); } catch (JspTagException e) { assertThat(e.getMessage(), is( "The value of field2 must be either true or false.")); } }
public static boolean toBoolean(String attributeValue, boolean defaultValue, String attributeName) throws JspTagException { if (StringUtils.hasText(attributeValue)) { if ("true".equalsIgnoreCase(attributeValue) || "false" .equalsIgnoreCase(attributeValue)) { return Boolean.parseBoolean(attributeValue); } else { throw new JspTagException("The value of " + attributeName + " must be either true or false."); } } return defaultValue; }
JspTagUtils { public static boolean toBoolean(String attributeValue, boolean defaultValue, String attributeName) throws JspTagException { if (StringUtils.hasText(attributeValue)) { if ("true".equalsIgnoreCase(attributeValue) || "false" .equalsIgnoreCase(attributeValue)) { return Boolean.parseBoolean(attributeValue); } else { throw new JspTagException("The value of " + attributeName + " must be either true or false."); } } return defaultValue; } }
JspTagUtils { public static boolean toBoolean(String attributeValue, boolean defaultValue, String attributeName) throws JspTagException { if (StringUtils.hasText(attributeValue)) { if ("true".equalsIgnoreCase(attributeValue) || "false" .equalsIgnoreCase(attributeValue)) { return Boolean.parseBoolean(attributeValue); } else { throw new JspTagException("The value of " + attributeName + " must be either true or false."); } } return defaultValue; } private  JspTagUtils(); }
JspTagUtils { public static boolean toBoolean(String attributeValue, boolean defaultValue, String attributeName) throws JspTagException { if (StringUtils.hasText(attributeValue)) { if ("true".equalsIgnoreCase(attributeValue) || "false" .equalsIgnoreCase(attributeValue)) { return Boolean.parseBoolean(attributeValue); } else { throw new JspTagException("The value of " + attributeName + " must be either true or false."); } } return defaultValue; } private  JspTagUtils(); static boolean toBoolean(String attributeValue, boolean defaultValue,
            String attributeName); }
JspTagUtils { public static boolean toBoolean(String attributeValue, boolean defaultValue, String attributeName) throws JspTagException { if (StringUtils.hasText(attributeValue)) { if ("true".equalsIgnoreCase(attributeValue) || "false" .equalsIgnoreCase(attributeValue)) { return Boolean.parseBoolean(attributeValue); } else { throw new JspTagException("The value of " + attributeName + " must be either true or false."); } } return defaultValue; } private  JspTagUtils(); static boolean toBoolean(String attributeValue, boolean defaultValue,
            String attributeName);  }