### Question:
CheckAllGroupPositionValidator implements ConstraintValidator<CheckAllGroupPosition, List<ClientQueryGroup>>,
        ValidationErrorDescriptorBuilder { @Override public boolean isValid(List<ClientQueryGroup> groups, ConstraintValidatorContext context) { if (groups.size() > 1) { if (isAllGroup(groups.get(0))) { return true; } for (ClientQueryGroup g : groups) { if (isAllGroup(g)) return false; } } return true; }  @Override void initialize(CheckAllGroupPosition constraintAnnotation); @Override boolean isValid(List<ClientQueryGroup> groups, ConstraintValidatorContext context); @Override ErrorDescriptor build(ConstraintViolation violation);  }### Answer:
@Test public void isValid_nullGroups_throwsException() { final ConstraintValidatorContext stub = mock(ConstraintValidatorContext.class); assertThrows( NullPointerException.class, new Executable() { @Override public void execute() { objectUnderTests.isValid( null, stub ); } } ); }
@Test public void isValid_emptyGroups_true() { ConstraintValidatorContext mock = mock(ConstraintValidatorContext.class); boolean isValid = objectUnderTests.isValid( Collections.<ClientQueryGroup>emptyList(), mock ); verifyZeroInteractions(mock); assertTrue(isValid); }
@Test public void isValid_oneElementInGroups_true() { ConstraintValidatorContext mock = mock(ConstraintValidatorContext.class); boolean isValid = objectUnderTests.isValid( Collections.singletonList( new ClientQueryGroup() ), mock ); verifyZeroInteractions(mock); assertTrue(isValid); }
@Test public void isValid_FirstElement_AllGroups_true() { ConstraintValidatorContext mock = mock(ConstraintValidatorContext.class); boolean isValid = objectUnderTests.isValid( Arrays.asList( new ClientQueryGroup.ClientAllGroup(), new ClientQueryGroup() ), mock ); verifyZeroInteractions(mock); assertTrue(isValid); }
@Test public void isValid_SecondElement_AllGroups_false() { ConstraintValidatorContext mock = mock(ConstraintValidatorContext.class); boolean isValid = objectUnderTests.isValid( Arrays.asList( new ClientQueryGroup(), new ClientQueryGroup.ClientAllGroup() ), mock ); verifyZeroInteractions(mock); assertFalse(isValid); }
@Test public void isValid_without_AllGroups_true() { ConstraintValidatorContext mock = mock(ConstraintValidatorContext.class); boolean isValid = objectUnderTests.isValid( Arrays.asList( new ClientQueryGroup(), new ClientQueryGroup() ), mock ); verifyZeroInteractions(mock); assertTrue(isValid); }