### Question:
VerhoeffIdentifierValidator extends BaseHyphenatedIdentifierValidator { @Override public String getValidIdentifier(String undecoratedIdentifier) throws UnallowedIdentifierException { String result = super.getValidIdentifier(undecoratedIdentifier); if (undecoratedIdentifier.length() != VERHOEFF_UNDECORATED_ID_LENGTH) { throw new UnallowedIdentifierException("Undecorated identifier must be " + VERHOEFF_UNDECORATED_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 getValidIdentifier_shouldGetValidIdentifier() { for (int i = 0; i < allowedIdentifiers.length; i++) { assertEquals(validator.getValidIdentifier(allowedIdentifiers[i]), allowedIdentifiers[i] + "-" + allowedIdentifiersCheckDigits[i]); } }
@Test public void getValidIdentifier_shouldFailWithInvalidIdentifiers() { for (String invalidIdentifier: invalidIdentifiers) { try { validator.getValidIdentifier(invalidIdentifier); fail("Identifier " + invalidIdentifier + " should have failed."); } catch (Exception e) { if (invalidIdentifier.length() == 0){ assertTrue(e.getMessage().matches("Identifier must contain at least one character\\.")); } else if (invalidIdentifier.indexOf(' ') > -1) { assertTrue(e.getMessage().matches("Identifier may not contain white space\\.")); } else if (invalidIdentifier.matches(".*[^\\d].*")) { assertTrue(e.getMessage().indexOf("is an invalid character") > 0); } else if (invalidIdentifier.length() != EXPECTED_RAW_IDENTIFIER_LENGTH) { assertTrue(e.getMessage().matches("Undecorated identifier must be 8 digits long\\.")); } else { fail("Unexpected message '" + e.getMessage() + "' seen for invalid identifier '" + invalidIdentifier + "'"); } } } }
@Test @Verifies(value = "should get valid identifier", method = "getValidIdentifier(String)") public void getValidIdentifier_shouldGetValidIdentifier() throws Exception { for (int i = 0; i < allowedIdentifiers.length; i++) { assertEquals(validator.getValidIdentifier(allowedIdentifiers[i]), allowedIdentifiers[i] + "-" + allowedIdentifiersCheckDigits[i]); } for (int j = 0; j < invalidIdentifiers.length; j++) { try { validator.getValidIdentifier(invalidIdentifiers[j]); fail("Identifier " + invalidIdentifiers[j] + " should have failed."); } catch (Exception e) {} } }