ConstraintServices { public ConstraintViolation[] extractViolations(ConstraintViolationException cve) { Set<javax.validation.ConstraintViolation<?>> constraintViolations = cve.getConstraintViolations(); List<ConstraintViolation> resultList = new ArrayList<>(); for (javax.validation.ConstraintViolation<?> constraintViolation : constraintViolations) { resultList.add(extractViolation(constraintViolation)); } return resultList.toArray(new ConstraintViolation[]{}); }  ConstraintViolation[] extractViolations(ConstraintViolationException cve);  }
@Test public void testExtractViolations() { System.out.println("extractViolations"); ConstraintViolationException cve = mock(ConstraintViolationException.class); Set<javax.validation.ConstraintViolation<?>> constraintViolations = new HashSet<>(); constraintViolations.add(mock(javax.validation.ConstraintViolation.class)); constraintViolations.add(mock(javax.validation.ConstraintViolation.class)); when(cve.getConstraintViolations()).thenReturn(constraintViolations); doReturn(mock(ConstraintViolation.class)).when(instance).extractViolation(any(javax.validation.ConstraintViolation.class)); ConstraintViolation[] result = instance.extractViolations(cve); assertThat(result).hasSize(2); }