### Question:
VariableNameTextBox extends AbstractValidatingTextBox { @Override public String isValidValue(final String value, final boolean isOnFocusLost) { if (invalidValues != null && !invalidValues.isEmpty()) { if (isOnFocusLost) { String err = testForInvalidValue(value); if (err != null && !err.isEmpty()) { return err; } } } if (regExp != null) { boolean isValid = this.regExp.test(value); if (!isValid) { String invalidChars = getInvalidCharsInName(value); return (isOnFocusLost ? invalidCharactersInNameErrorMessage : invalidCharacterTypedMessage) + ": " + invalidChars; } } return null; } VariableNameTextBox(); void setInvalidValues(final Set<String> invalidValues,
                                 final boolean isCaseSensitive,
                                 final String invalidValueErrorMessage); void setRegExp(final String pattern,
                          final String invalidCharactersInNameErrorMessage,
                          final String invalidCharacterTypedMessage); @Override String isValidValue(final String value,
                               final boolean isOnFocusLost);  }### Answer:
@Test public void testIsValidValue() { String isValidResult; isValidResult = textBox.isValidValue("a", true); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("a", false); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("-", true); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("-", false); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("_", true); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("_", false); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("aBc", true); if (caseSensitive) { assertEquals(null, isValidResult); } else { assertEquals(ERROR_MESSAGE, isValidResult); } isValidResult = textBox.isValidValue("aBc", false); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("CdE", true); assertEquals(ERROR_MESSAGE, isValidResult); isValidResult = textBox.isValidValue("CdE", false); assertEquals(null, isValidResult); isValidResult = textBox.isValidValue("a#$%1", true); assertEquals(ERROR_MESSAGE, isValidResult); isValidResult = textBox.isValidValue("a#$%1", false); assertEquals(ERROR_TYPED + ": #$%", isValidResult); isValidResult = textBox.isValidValue("a.", true); assertEquals(ERROR_MESSAGE, isValidResult); isValidResult = textBox.isValidValue("a.", false); assertEquals(ERROR_TYPED + ": .", isValidResult); }