### Question:
CepValidator implements ConstraintValidator<Cep, String> { @Override public boolean isValid(String cep, final ConstraintValidatorContext context) { boolean result = false; if ( cep == null || "".equals(cep) ) { result = true; } else { Pattern pattern = Pattern.compile("^(([0-9]{2}\\.[0-9]{3}-[0-9]{3})|([0-9]{2}[0-9]{3}-[0-9]{3})|([0-9]{8}))$"); Matcher matcher = pattern.matcher(cep); result = matcher.find(); } return result; }  @Override void initialize(final Cep constraintAnnotation); @Override boolean isValid(String cep, final ConstraintValidatorContext context);  }### Answer:
@Test public void testValidacaoCepCorreto() { CepValidator validator = new CepValidator(); Assert.assertTrue(validator.isValid("40290280", null)); Assert.assertTrue(validator.isValid("40290281", null)); Assert.assertTrue(validator.isValid("40.290-280", null)); Assert.assertTrue(validator.isValid("40290-280", null)); }
@Test public void testValidacaoCepIncorreto() { CepValidator validator = new CepValidator(); Assert.assertFalse(validator.isValid("4029028", null)); Assert.assertFalse(validator.isValid("4029028029", null)); Assert.assertFalse(validator.isValid("40.290280", null)); Assert.assertFalse(validator.isValid("40aa290-280", null)); Assert.assertFalse(validator.isValid("aa290280", null)); Assert.assertFalse(validator.isValid("40?290-280", null)); }