Class Assertions


  • @API(status=INTERNAL,
         since="2020.0.0")
    public final class Assertions
    extends Object
    Assertions used throughout the Cypher-DSL. Mostly copied over from org.springframework.util.Assert. Thanks to the original authors: Keith Donald, Juergen Hoeller, Sam Brannen, Colin Sampaleanu and Rob Harrop. Not supported for external use in anyway.
    Since:
    2020.0.0
    • Method Detail

      • hasText

        public static void hasText​(String text,
                                   String message)
        Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.
        Assert.hasText(name, "'name' must not be empty");
        Parameters:
        text - the String to check
        message - the exception message to use if the assertion fails
        Throws:
        IllegalArgumentException - if the text does not contain valid text content
      • isTrue

        public static void isTrue​(boolean expression,
                                  String message)
        Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false.
        Assert.isTrue(i > 0, "The value must be greater than zero");
        Parameters:
        expression - a boolean expression
        message - the exception message to use if the assertion fails
        Throws:
        IllegalArgumentException - if expression is false
      • notNull

        public static void notNull​(Object object,
                                   String message)
        Assert that an object is not null.
        Assert.notNull(clazz, "The class must not be null");
        Parameters:
        object - the object to check
        message - the exception message to use if the assertion fails
        Throws:
        IllegalArgumentException - if the object is null
      • isInstanceOf

        public static void isInstanceOf​(Class<?> type,
                                        Object obj,
                                        String message)
        Assert that the provided object is an instance of the provided class.
        Assert.instanceOf(Foo.class, foo, "Foo expected");
        Parameters:
        type - the type to check against
        obj - the object to check
        message - the exception message to use if the assertion fails
        Throws:
        IllegalArgumentException - if the object is not an instance of type
      • notEmpty

        public static void notEmpty​(Object[] array,
                                    String message)
        Assert that an array contains elements; that is, it must not be null and must contain at least one element.
        Assert.notEmpty(array, "The array must contain elements");
        Parameters:
        array - the array to check
        message - the exception message to use if the assertion fails
        Throws:
        IllegalArgumentException - if the object array is null or contains no elements