### Question:
TituloEleitoralValidator implements Validator<String> { public void assertValid(String tituloDeEleitor) { List<ValidationMessage> errors = getInvalidValues(tituloDeEleitor); if (!errors.isEmpty()) { throw new InvalidStateException(errors); } } TituloEleitoralValidator();  TituloEleitoralValidator(boolean isFormatted);  TituloEleitoralValidator(MessageProducer messageProducer,boolean isFormatted);  TituloEleitoralValidator(MessageProducer messageProducer); boolean isEligible(String value); void assertValid(String tituloDeEleitor); List<ValidationMessage> invalidMessagesFor(String tituloDeEleitor); @Override String generateRandomValid(); static final Pattern FORMATED; static final Pattern UNFORMATED; }### Answer:
@Test public void shouldValidateCorrectString() { for (String validString : validStrings) { validator.assertValid(validString); } }
@Test public void shouldValidateCorrectFormattedString() { for (String validString : validStringsFormatted) { validatorFormatted.assertValid(validString); } }
@Test public void shouldNotValidateStringWithFirstCheckDigitWrong() { for (String invalidString : invalidFirstDigitStrings) { try { validator.assertValid(invalidString); Assert.fail("O titulo eleitoral " + invalidString + " deve ser considerado inválido!"); } catch (InvalidStateException e) { } } }
@Test public void shouldNotValidateStringWithSecondCheckDigitWrong() { for (String invalidString : invalidSecondDigitStrings) { try { validator.assertValid(invalidString); Assert.fail("O titulo eleitoral " + invalidString + " deve ser considerado inválido!"); } catch (InvalidStateException e) { } } }
@Test(expected = InvalidStateException.class) public void shouldNotValidateStringMoreDigits() { validator.assertValid(validStrings[0] + "0"); }
@Test(expected = InvalidStateException.class) public void shouldNotValidateStringWithCodigoDeEstadoInvalidoMenorDoQueUm() { validator.assertValid("471235380051"); }
@Test(expected = InvalidStateException.class) public void shouldNotValidateStringWithCodigoDeEstadoInvalidoMaiorDoQue28() { validator.assertValid("815155812960"); }