/** * Invokes validation on inner context. Always returns <code>true</code> since * inner context violations will be appended to provided validator. */ @Override public boolean isValid(final ValidationConstraintContext vcc, final Object value) { if (value == null) { return true; } vcc.validateWithin(targetValidationContext, value); return true; } }
@Test void testValidateWithin() throws Exception { Vtor vtor = mock(Vtor.class); Object target = new Object(); ValidationConstraintContext context = new ValidationConstraintContext(vtor, target, "niceConstraint"); ValidationContext vctx = mock(ValidationContext.class); Object value = new Object(); //when context.validateWithin(vctx, value); //then verify(vtor).validate(eq(vctx), eq(value), eq("niceConstraint")); } }
@Test void testIsValid_withNullValue() { //given ValidationContext targetValidationContext = mock(ValidationContext.class); AssertValidConstraint assertValidConstraint = new AssertValidConstraint(targetValidationContext); ValidationConstraintContext vcc = mockContext(); //when boolean valid = assertValidConstraint.isValid(vcc, null); //then assertTrue(valid); verify(vcc, never()).validateWithin(eq(targetValidationContext), isNull()); }
@Test void testIsValid() { //given ValidationContext targetValidationContext = mock(ValidationContext.class); AssertValidConstraint assertValidConstraint = new AssertValidConstraint(targetValidationContext); ValidationConstraintContext vcc = mockContext(); Object someValue = new Object(); //this method is empty so nothing to check assertValidConstraint.configure(null); //when validate some value boolean valid = assertValidConstraint.isValid(vcc, someValue); //then validateWithin must be called for validated value assertTrue(valid); //validateWithin must be called for validated value verify(vcc).validateWithin(eq(targetValidationContext), eq(someValue)); } }
/** * Invokes validation on inner context. Always returns <code>true</code> since * inner context violations will be appended to provided validator. */ public boolean isValid(ValidationConstraintContext vcc, Object value) { if (value == null) { return true; } vcc.validateWithin(targetValidationContext, value); return true; } }