@Test public void testValidateAge() throws Exception { person.setAge(30); person.setName("Terrence"); new ValidationSuccess<>(person) .flatMap(PersonValidator::validateAge) .flatMap(PersonValidator::validateName); }
@Test public void testValidateAgeFailed() throws Exception { person.setAge(0); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure); person.setAge(130); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure); person.setAge(-1); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationFailure); }
@Test public void testValidateAgePassed() throws Exception { person.setAge(1); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess); person.setAge(129); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess); person.setAge(100); assertTrue("Incorrect age", PersonValidator.validateAge(person) instanceof ValidationSuccess); }