Class ConstraintViolationAssert

java.lang.Object
org.hibernate.validator.testutil.ConstraintViolationAssert

public final class ConstraintViolationAssert extends Object
This class provides useful functions to assert correctness of constraint violations raised during tests.
Author:
Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Hardy Ferentschik, Gunnar Morling
  • Method Details

    • assertCorrectConstraintTypes

      public static void assertCorrectConstraintTypes(Set<? extends ConstraintViolation<?>> violations, Class<?>... expectedConstraintTypes)
      Asserts that the violated constraint type in the violation list matches exactly the expected constraint types list.
      Parameters:
      violations - The violation list to verify.
      expectedConstraintTypes - The expected constraint types.
    • assertCorrectPropertyPathStringRepresentations

      public static void assertCorrectPropertyPathStringRepresentations(Set<? extends ConstraintViolation<?>> violations, String... expectedPropertyPaths)
      Asserts that the given list of constraint violation paths matches the list of expected property paths.
      Parameters:
      violations - The violation list to verify.
      expectedPropertyPaths - The expected property paths.
    • assertThat

      public static ConstraintViolationAssert.ConstraintViolationSetAssert assertThat(Set<? extends ConstraintViolation<?>> actualViolations)
    • assertNoViolations

      public static void assertNoViolations(Set<? extends ConstraintViolation<?>> violations)
      Asserts that the given violation list has no violations (is empty).
      Parameters:
      violations - The violation list to verify.
    • assertNoViolations

      public static void assertNoViolations(Set<? extends ConstraintViolation<?>> violations, String message)
      Asserts that the given violation list has no violations (is empty).
      Parameters:
      violations - The violation list to verify.
    • assertConstraintTypes

      public static void assertConstraintTypes(Set<? extends ConstraintDescriptor<?>> descriptors, Class<?>... expectedConstraintTypes)
    • assertPathEquals

      public static void assertPathEquals(Path path, ConstraintViolationAssert.PathExpectation expectedPath)
      Asserts that the path matches the expected path.
      Parameters:
      path - The path under test
      expectedPath - The expected path
    • pathsAreEqual

      public static boolean pathsAreEqual(Path p1, Path p2)
      Checks that two property paths are equal.
      Parameters:
      p1 - The first property path.
      p2 - The second property path.
      Returns:
      true if the given paths are equal, false otherwise.
    • pathWith

    • violationOf

      public static ConstraintViolationAssert.ViolationExpectation violationOf(Class<? extends Annotation> constraintType)