Package org.hibernate.validator.testutil
Class ConstraintViolationAssert
java.lang.Object
org.hibernate.validator.testutil.ConstraintViolationAssert
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
A property path expected to be returned by a givenConstraintViolation
.static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertConstraintTypes
(Set<? extends ConstraintDescriptor<?>> descriptors, Class<?>... expectedConstraintTypes) 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.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.static void
assertNoViolations
(Set<? extends ConstraintViolation<?>> violations) Asserts that the given violation list has no violations (is empty).static void
assertNoViolations
(Set<? extends ConstraintViolation<?>> violations, String message) Asserts that the given violation list has no violations (is empty).static void
assertPathEquals
(Path path, ConstraintViolationAssert.PathExpectation expectedPath) Asserts that the path matches the expected path.assertThat
(Set<? extends ConstraintViolation<?>> actualViolations) static boolean
pathsAreEqual
(Path p1, Path p2) Checks that two property paths are equal.pathWith()
violationOf
(Class<? extends Annotation> constraintType)
-
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
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 testexpectedPath
- The expected path
-
pathsAreEqual
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)
-