Class Assertions


  • @API(status=INTERNAL,
         since="2020.0.0")
    public final class Assertions
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void hasText​(java.lang.String text, java.lang.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.
      static void isInstanceOf​(java.lang.Class<?> type, java.lang.Object obj, java.lang.String message)
      Assert that the provided object is an instance of the provided class.
      static void isTrue​(boolean expression, java.lang.String message)
      Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false.
      static void notEmpty​(java.lang.Object[] array, java.lang.String message)
      Assert that an array contains elements; that is, it must not be null and must contain at least one element.
      static void notNull​(java.lang.Object object, java.lang.String message)
      Assert that an object is not null.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • hasText

        public static void hasText​(java.lang.String text,
                                   java.lang.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:
        java.lang.IllegalArgumentException - if the text does not contain valid text content
      • isTrue

        public static void isTrue​(boolean expression,
                                  java.lang.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:
        java.lang.IllegalArgumentException - if expression is false
      • notNull

        public static void notNull​(java.lang.Object object,
                                   java.lang.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:
        java.lang.IllegalArgumentException - if the object is null
      • isInstanceOf

        public static void isInstanceOf​(java.lang.Class<?> type,
                                        java.lang.Object obj,
                                        java.lang.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:
        java.lang.IllegalArgumentException - if the object is not an instance of type
      • notEmpty

        public static void notEmpty​(java.lang.Object[] array,
                                    java.lang.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:
        java.lang.IllegalArgumentException - if the object array is null or contains no elements