### Question:
VerhoeffIdentifierValidator extends BaseHyphenatedIdentifierValidator { @Override public boolean isValid(String identifier) throws UnallowedIdentifierException { boolean result = super.isValid(identifier); if (Character.isDigit(identifier.charAt(identifier.length() - 1))) { throw new UnallowedIdentifierException("Check digit can not be numeric."); } if (identifier.length() != VERHOEFF_ID_LENGTH) { throw new UnallowedIdentifierException("Identifier must be " + VERHOEFF_ID_LENGTH + " digits long."); } return result; } VerhoeffIdentifierValidator(); @Override String getAllowedCharacters(); @Override String getName(); @Override boolean isValid(String identifier); @Override String getValidIdentifier(String undecoratedIdentifier);  }### Answer:
@Test public void isValid_shouldFailWithInvalidIdentifiers() { for (String invalidIdentifier: invalidIdentifiers) { try { validator.isValid(invalidIdentifier); fail("Identifier " + invalidIdentifier + " should have failed."); } catch (Exception e) { } } }
@Test public void isValid_shouldFailWithInvalidSuffixes() { for (String allowedIdentifier : allowedIdentifiers) { try { validator.isValid(allowedIdentifier + "-X"); fail("Identifier " + allowedIdentifier + " should have failed."); } catch (Exception e) { } try { validator.isValid(allowedIdentifier + "-10"); fail("Identifier " + allowedIdentifier + " should have failed."); } catch (Exception e) { } } }
@Test public void isValid_shouldPassWithValidSuffixes() { for (int i = 0; i < allowedIdentifiers.length; i++) { assertTrue(validator.isValid(allowedIdentifiers[i] + "-" + allowedIdentifiersCheckDigits[i])); } }
@Test public void isValid_shouldFailWithIncorrectlyCalculatedSuffixes() { for (String allowedIdentifier : allowedIdentifiers) { assertFalse(validator.isValid(allowedIdentifier + "-" + unusedCheckDigit)); } }
@Test public void isValid_shouldFailWithNumericSuffixes() { for (int i = 0; i < allowedIdentifiers.length; i++) { try { validator.isValid(allowedIdentifiers[i] + "-" + allowedIdentifiersCheckDigitsInt[i]); fail("Identifier " + allowedIdentifiers[i] + " should have failed."); } catch (Exception e) { } } }
@Test public void shouldIsValid() { for (int j = 0; j < invalidIdentifiers.length; j++) { try { validator.isValid(invalidIdentifiers[j]); fail("Identifier " + invalidIdentifiers[j] + " should have failed."); } catch (Exception e) {} } for (int j = 0; j < invalidIdentifiers.length; j++) { try { validator.isValid(invalidIdentifiers[j] + "-H"); fail("Identifier " + invalidIdentifiers[j] + " should have failed."); } catch (Exception e) {} } for (int i = 0; i < allowedIdentifiers.length; i++) { try { validator.isValid(allowedIdentifiers[i] + "-X"); fail("Identifier " + allowedIdentifiers[i] + " should have failed."); } catch (Exception e) {} try { validator.isValid(allowedIdentifiers[i] + "-10"); fail("Identifier " + allowedIdentifiers[i] + " should have failed."); } catch (Exception e) {} } for (int j = 0; j < invalidIdentifiers.length; j++) { try { validator.isValid(allowedIdentifiers[j] + "-" + allowedIdentifiersCheckDigitsInt[j]); fail("Identifier " + allowedIdentifiers[j] + " should have failed."); } catch (Exception e) {} } for (int i = 0; i < allowedIdentifiers.length; i++) { assertFalse(validator.isValid(allowedIdentifiers[i] + "-" + unusedCheckDigit)); } for (int i = 0; i < allowedIdentifiers.length; i++) { assertTrue(validator.isValid(allowedIdentifiers[i] + "-" + allowedIdentifiersCheckDigits[i])); } }