ConstraintViolations { public static ConstraintViolationMetadata getMetadata(ConstraintViolation<?> violation) { Annotation[] annotations = getAnnotations(violation); return new ConstraintViolationMetadata(violation, annotations); } private  ConstraintViolations(); static ConstraintViolationMetadata getMetadata(ConstraintViolation<?> violation);  }
@Test public void shouldSupportControllerFields() { SomeController controller = new SomeController(); controller.setControllerField(INVALID); long methodParameter = VALID; BeanParamBean paramBean = new BeanParamBean(); paramBean.setBeanParamField(VALID); List<ConstraintViolation<?>> violations = simulateValidation( controller, "someControllerMethod", methodParameter, paramBean); Assert.assertEquals(1, violations.size()); Assert.assertEquals("controller-field", ConstraintViolations.getMetadata(violations.get(0)).getParamName().orElse(null)); }
@Test public void shouldSupportMethodParameters() { SomeController controller = new SomeController(); controller.setControllerField(VALID); long methodParameter = INVALID; BeanParamBean paramBean = new BeanParamBean(); paramBean.setBeanParamField(VALID); List<ConstraintViolation<?>> violations = simulateValidation( controller, "someControllerMethod", methodParameter, paramBean); Assert.assertEquals(1, violations.size()); Assert.assertEquals("method-parameter", ConstraintViolations.getMetadata(violations.get(0)).getParamName().orElse(null)); }
@Test public void shouldSupportBeanParamBeans() { SomeController controller = new SomeController(); controller.setControllerField(VALID); long methodParameter = VALID; BeanParamBean paramBean = new BeanParamBean(); paramBean.setBeanParamField(INVALID); List<ConstraintViolation<?>> violations = simulateValidation( controller, "someControllerMethod", methodParameter, paramBean); Assert.assertEquals(1, violations.size()); Assert.assertEquals("bean-param-field", ConstraintViolations.getMetadata(violations.get(0)).getParamName().orElse(null)); }