Class Assert


  • public final class Assert
    extends java.lang.Object
    Exposes useful methods for testing method call parameters and raising a IllegalArgumentException unchecked exception.
    Since:
    2.0.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Assert getInstance()
      Gets the unique instance.
      Assert greaterOrEqual​(java.lang.Integer number, int minValue, java.lang.String name)
      Assert that an integer is not null and is greater than or equal to minValue.
      Assert isEqual​(java.lang.Integer number, int value, java.lang.String name)
      Assert that an integer is equal to value.
      Assert isHexString​(java.lang.String hex, java.lang.String name)
      Assert that a string has a valid hexadecimal format.
      Assert isInRange​(java.lang.Integer number, int minValue, int maxValue, java.lang.String name)
      Assert that an integer is not null and is in the range minValue, maxValue.
      Assert isTrue​(java.lang.Boolean condition, java.lang.String name)
      Assert that a condition is true.
      Assert notEmpty​(byte[] obj, java.lang.String name)
      Assert that a byte array is not null and not empty.
      Assert notEmpty​(java.lang.String obj, java.lang.String name)
      Assert that the input string is not null and not empty.
      Assert notEmpty​(java.util.Collection<?> obj, java.lang.String name)
      Assert that a collection of objects is not null and not empty.
      Assert notNull​(java.lang.Object obj, java.lang.String name)
      Assert that the input object is not null.
      • Methods inherited from class java.lang.Object

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

      • getInstance

        public static Assert getInstance()
        Gets the unique instance.
        Returns:
        the instance
      • notNull

        public Assert notNull​(java.lang.Object obj,
                              java.lang.String name)
        Assert that the input object is not null.
        Parameters:
        obj - the object to check
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if object is null
        Since:
        2.0.0
      • notEmpty

        public Assert notEmpty​(java.lang.String obj,
                               java.lang.String name)
        Assert that the input string is not null and not empty.
        Parameters:
        obj - the object to check
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if object is null or empty
        Since:
        2.0.0
      • notEmpty

        public Assert notEmpty​(java.util.Collection<?> obj,
                               java.lang.String name)
        Assert that a collection of objects is not null and not empty.
        Parameters:
        obj - the object to check
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if object is null or empty
        Since:
        2.0.0
      • notEmpty

        public Assert notEmpty​(byte[] obj,
                               java.lang.String name)
        Assert that a byte array is not null and not empty.
        Parameters:
        obj - the object to check
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if object is null or empty
        Since:
        2.0.0
      • isTrue

        public Assert isTrue​(java.lang.Boolean condition,
                             java.lang.String name)
        Assert that a condition is true.
        Parameters:
        condition - the condition to check
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if condition is null or false
        Since:
        2.0.0
      • greaterOrEqual

        public Assert greaterOrEqual​(java.lang.Integer number,
                                     int minValue,
                                     java.lang.String name)
        Assert that an integer is not null and is greater than or equal to minValue.
        Parameters:
        number - the number to check
        minValue - the min accepted value
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if number is null or has a value less than minValue.
        Since:
        2.0.0
      • isEqual

        public Assert isEqual​(java.lang.Integer number,
                              int value,
                              java.lang.String name)
        Assert that an integer is equal to value.
        Parameters:
        number - the number to check
        value - the expected value
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if number is null or has a value less than minValue.
        Since:
        2.0.0
      • isInRange

        public Assert isInRange​(java.lang.Integer number,
                                int minValue,
                                int maxValue,
                                java.lang.String name)
        Assert that an integer is not null and is in the range minValue, maxValue.
        Parameters:
        number - the number to check
        minValue - the min accepted value
        maxValue - the max accepted value
        name - the object name
        Returns:
        the current instance
        Throws:
        java.lang.IllegalArgumentException - if number is null or is out of range.
        Since:
        2.0.0
      • isHexString

        public Assert isHexString​(java.lang.String hex,
                                  java.lang.String name)
        Assert that a string has a valid hexadecimal format.
        Parameters:
        hex - The string to check.
        name - The object name.
        Returns:
        The current instance.
        Throws:
        java.lang.IllegalArgumentException - If the provided string is null, empty or has not a valid hexadecimal format.
        Since:
        2.1.0