use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project api-core by ca-cwds.
the class SystemCodeIdValidatorTest method isValid_Args__Object__ValidWhenIgnoredValue0.
@Test
public void isValid_Args__Object__ValidWhenIgnoredValue0() throws Exception {
ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
when(anno.required()).thenReturn(false);
when(anno.ignoreable()).thenReturn(true);
when(anno.ignoredValue()).thenReturn(0);
when(anno.category()).thenReturn("ETHNCTYC");
target.initialize(anno);
Set<String> validCodes = new HashSet<>();
validCodes.add("0");
ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
when(builder.addPropertyNode(any())).thenReturn(mock(NodeBuilderCustomizableContext.class));
when(context_.buildConstraintViolationWithTemplate(any())).thenReturn(builder);
boolean actual = target.isValid(validCodes, context_);
boolean expected = true;
assertThat(actual, is(equalTo(expected)));
}
use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project api-core by ca-cwds.
the class SystemCodeIdValidatorTest method isValid_Args__Object__InvalidCollectionValues.
@Test
public void isValid_Args__Object__InvalidCollectionValues() throws Exception {
ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
when(anno.required()).thenReturn(true);
when(anno.category()).thenReturn("ETHNCTYC");
target.initialize(anno);
Set<String> validCodes = new HashSet<>();
validCodes.add("0");
ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
when(builder.addPropertyNode(any())).thenReturn(mock(NodeBuilderCustomizableContext.class));
when(context_.buildConstraintViolationWithTemplate(any())).thenReturn(builder);
boolean actual = target.isValid(validCodes, context_);
boolean expected = false;
assertThat(actual, is(equalTo(expected)));
}
use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project syndesis by syndesisio.
the class UniquePropertyValidatorTest method shouldAscertainPropertyUniqueness.
@Test
public void shouldAscertainPropertyUniqueness() {
final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));
assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
Aggregations