### Question:
NITValidator implements Validator<String> { public void assertValid(String nit) { List<ValidationMessage> errors = getInvalidValues(nit); if (!errors.isEmpty()) { throw new InvalidStateException(errors); } } NITValidator();  NITValidator(boolean isFormatted);  NITValidator(MessageProducer messageProducer, boolean isFormatted); boolean isEligible(String value); void assertValid(String nit); List<ValidationMessage> invalidMessagesFor(String nit); @Override String generateRandomValid(); static final Pattern FORMATED; static final Pattern UNFORMATED; }### Answer:
@Test public void shouldNotValidateNITWithInvalidCharacter() { NITValidator validator = new NITValidator(); String value = "1111111a111"; try { validator.assertValid(value); fail(); } catch (InvalidStateException e) { assertTrue(e.getInvalidMessages().size() == 1); assertMessage(e, INVALID_DIGITS); } }
@Test public void shouldNotValidateNITWithLessDigitsThanAllowed() { NITValidator validator = new NITValidator(); String value = "1234567890"; try { validator.assertValid(value); fail(); } catch (InvalidStateException e) { assertTrue(e.getInvalidMessages().size() == 1); assertMessage(e, INVALID_DIGITS); } }
@Test public void shouldNotValidateNITWithMoreDigitsThanAlowed() { NITValidator validator = new NITValidator(); String value = "123456789012"; try { validator.assertValid(value); fail(); } catch (InvalidStateException e) { assertTrue(e.getInvalidMessages().size() == 1); assertMessage(e, INVALID_DIGITS); } }
@Test public void shouldNotValidateNITCheckDigitsWithCheckDigitWrong() { NITValidator validator = new NITValidator(); String value = "24843803470"; try { validator.assertValid(value); fail(); } catch (InvalidStateException e) { assertTrue(e.getInvalidMessages().size() == 1); assertMessage(e, INVALID_CHECK_DIGITS); } }
@Test public void shouldValidateValidNIT() { NITValidator validator = new NITValidator(); validator.assertValid("12345678919"); validator.assertValid("34608514300"); validator.assertValid("47393545608"); }
@Test public void shouldValidateNullNIT() { NITValidator validator = new NITValidator(); String value = null; validator.assertValid(value); }
@Test public void shouldValidateValidFormattedNIT() { NITValidator validator = new NITValidator(true); String value = "123.45678.91-9"; validator.assertValid(value); }
@Test public void shouldNotValidateValidUnformattedNIT() { NITValidator validator = new NITValidator(true); String value = "12345678919"; try { validator.assertValid(value); fail(); } catch (InvalidStateException e) { assertTrue(e.getInvalidMessages().size() == 1); assertMessage(e, INVALID_FORMAT); } }