Class Assert


  • public final class Assert
    extends java.lang.Object
    • 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 has valid text content; that is, it must not be null and must contain at least one non-whitespace character.
      static void isTrue​(boolean expression, java.lang.String message)
      Assert a boolean expression, throwing IllegalArgumentException if the test result is false.
      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

      • isTrue

        public static void isTrue​(boolean expression,
                                  java.lang.String message)
        Assert a boolean expression, throwing IllegalArgumentException if the test result is 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
      • hasText

        public static void hasText​(java.lang.String text,
                                   java.lang.String message)
        Assert that the given String has 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
        See Also:
        Strings.hasText(java.lang.CharSequence)