BooleanTextBox extends AbstractRestrictedEntryTextBox { @Override public boolean isValidValue(final String value, final boolean isOnFocusLost) { return (!isOnFocusLost && "-".equals(value)) || (value.trim().isEmpty() && allowEmptyValue) || Objects.equals(value.toLowerCase(), Boolean.TRUE.toString()) || Objects.equals(value.toLowerCase(), Boolean.FALSE.toString()); } BooleanTextBox(final boolean allowEmptyValue); @Override boolean isValidValue(final String value,
                                final boolean isOnFocusLost);  }
@Test public void emptyValues() { assertTrue(new BooleanTextBox(true).isValidValue("", false)); assertFalse(new BooleanTextBox(false).isValidValue("", false)); }
@Test public void focusLost() { assertFalse(new BooleanTextBox(true).isValidValue("-", true)); assertFalse(new BooleanTextBox(false).isValidValue("-", true)); assertTrue(new BooleanTextBox(false).isValidValue("-", false)); assertTrue(new BooleanTextBox(true).isValidValue("-", false)); }
@Test public void values() { assertFalse(new BooleanTextBox(true).isValidValue("blaa", false)); assertTrue(new BooleanTextBox(false).isValidValue("true", false)); assertTrue(new BooleanTextBox(false).isValidValue("false", false)); assertTrue(new BooleanTextBox(false).isValidValue("TRUE", false)); assertTrue(new BooleanTextBox(false).isValidValue("FALSE", false)); }