FinancingRoundNotCollidingValidator implements ConstraintValidator<FinancingRoundNotColliding, FinancingRound> { @Override public boolean isValid(final FinancingRound financingRound, ConstraintValidatorContext context) { for (FinancingRoundEntity financingRoundEntity : financingRoundRepository.findAll()) { if (!financingRoundEntity.getStartDate().isAfter(financingRound.getEndDate()) && !financingRoundEntity.getEndDate().isBefore(financingRound.getStartDate())) { context.buildConstraintViolationWithTemplate("non-colliding").addConstraintViolation(); return false; } } return true; }  @Override void initialize(FinancingRoundNotColliding constraintAnnotation); @Override boolean isValid(final FinancingRound financingRound, ConstraintValidatorContext context);  }
@Test public void testIsValidBefore() throws Exception { assertTrue(financingRoundNotCollidingValidator.isValid(financingRound(1, 9), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsValidAfter() throws Exception { assertTrue(financingRoundNotCollidingValidator.isValid(financingRound(21, 25), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsInValidWhenTouchingAtStart() throws Exception { assertFalse(financingRoundNotCollidingValidator.isValid(financingRound(1, 10), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsInValidWhenTouchingAtEnd() throws Exception { assertFalse(financingRoundNotCollidingValidator.isValid(financingRound(20, 25), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsInValidWhenOverlappingStart() throws Exception { assertFalse(financingRoundNotCollidingValidator.isValid(financingRound(1, 11), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsInValidWhenOverlappingEnd() throws Exception { assertFalse(financingRoundNotCollidingValidator.isValid(financingRound(19, 25), ValidatorTestUtil.constraintValidatorContext())); }
@Test public void testIsInValidWhenInBetween() throws Exception { assertFalse(financingRoundNotCollidingValidator.isValid(financingRound(11, 19), ValidatorTestUtil.constraintValidatorContext())); }