### Question:
LengthValidator implements Validator<Object> { public List<ValidationMessage> invalidMessagesFor(Object object) { List<ValidationMessage> messages = new ArrayList<ValidationMessage>(); messages.addAll(base.generateValidationMessages(getInvalidValuesFor(object))); return messages; } LengthValidator(int validLength);  LengthValidator(MessageProducer messageProducer, int validLength); void assertValid(Object object); List<ValidationMessage> invalidMessagesFor(Object object); boolean isEligible(Object object); @Override Object generateRandomValid();  }### Answer:
@Test public void shouldReturnCorrectValidationMessage() { Mockery mockery = new Mockery(); final MessageProducer messageProducer = mockery.mock(MessageProducer.class); LengthValidator lengthValidator = new LengthValidator(messageProducer, 2); String message = "O tamanho da entrada é inválido."; final ValidationMessage validationMessage = new SimpleValidationMessage(message); mockery.checking(new Expectations() { { one(messageProducer).getMessage(with(equal(new LengthError(2)))); will(returnValue(validationMessage)); } }); List<ValidationMessage> invalidMessages = lengthValidator.invalidMessagesFor(12345); Assert.assertEquals(1, invalidMessages.size()); Assert.assertEquals(message, invalidMessages.get(0).getMessage()); }
@Test public void shouldReturnPrettySimpleMessageValidation() { LengthValidator lengthValidator = new LengthValidator(2); List<ValidationMessage> invalidMessages = lengthValidator.invalidMessagesFor(12345); Assert.assertEquals(1, invalidMessages.size()); Assert.assertEquals("LengthError : INVALID LENGTH", invalidMessages.get(0).getMessage()); }