Class Assert


  • public class Assert
    extends java.lang.Object
    Utility to make asserts.

    In most case this asserts verify if the object is null. There are a variety of methods that throw differents exceptions.
    One of the thrown exception is AssertException, but this is not mandatory.

    If some of this methods throw exception this is usually due to a software error, normally a exception that the user-programmer has not fullfilled the contract.
    The messages does not have to specify the place where contract is break or which contract is broken. The trace (that always is printed) indicate the place and the exception class. In the doc of method that throw the exception you can obtain more info about it.
    The names and behaviour match with JUnit, the difference is the thrown exceptions.

    Author:
    Javier Paniza
    • Constructor Summary

      Constructors 
      Constructor Description
      Assert()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void arg​(java.lang.Object o)
      Verify argument.
      static void arg​(java.lang.Object o1, java.lang.Object o2)
      Verify arguments.
      static void arg​(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3)
      Verify arguments.
      static void arg​(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4)
      Verify arguments.
      static void arg​(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5)
      Verify arguments.
      static void arg​(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6)
      Verify arguments.
      static void arg​(java.lang.Object o1, java.lang.Object o2, java.lang.Object o3, java.lang.Object o4, java.lang.Object o5, java.lang.Object o6, java.lang.Object o7)
      Verify arguments.
      static void assertEquals​(double expected, double actual, double delta)
      Asserts that two doubles are equal.
      static void assertEquals​(long expected, long actual)
      Asserts that two longs are equal.
      static void assertEquals​(java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects are equal.
      static void assertEquals​(java.lang.String message, double expected, double actual, double delta)
      Asserts that two doubles are equal.
      static void assertEquals​(java.lang.String message, long expected, long actual)
      Asserts that two longs are equal.
      static void assertEquals​(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects are equal.
      static void assertNotNull​(java.lang.Object object)
      Asserts that an object isn't null.
      static void assertNotNull​(java.lang.String message, java.lang.Object object)
      Asserts that an object isn't null.
      static void assertNull​(java.lang.Object object)
      Asserts that an object is null.
      static void assertNull​(java.lang.String message, java.lang.Object object)
      Asserts that an object is null.
      static void assertSame​(java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects refer to the same object.
      static void assertSame​(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects refer to the same object.
      static void assertTrue​(boolean condition)
      Asserts that a condition is true.
      static void assertTrue​(java.lang.String message, boolean condition)
      Asserts that a condition is true.
      static void fail()
      Throws a AssertException and print the trace.
      static void fail​(java.lang.String message)
      Throws a AssertException and print the trace.
      • Methods inherited from class java.lang.Object

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

      • Assert

        public Assert()
    • Method Detail

      • arg

        public static final void arg​(java.lang.Object o)
        Verify argument.
        Throws:
        java.lang.IllegalArgumentException - If o == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     java.lang.Object o3)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null || o3 == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     java.lang.Object o3,
                                     java.lang.Object o4)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null || o3 == null || o4 == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     java.lang.Object o3,
                                     java.lang.Object o4,
                                     java.lang.Object o5)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null || o3 == null || o4 == null || o5 == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     java.lang.Object o3,
                                     java.lang.Object o4,
                                     java.lang.Object o5,
                                     java.lang.Object o6)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null || o3 == null || o4 == null || o5 == null || o6 == null.
      • arg

        public static final void arg​(java.lang.Object o1,
                                     java.lang.Object o2,
                                     java.lang.Object o3,
                                     java.lang.Object o4,
                                     java.lang.Object o5,
                                     java.lang.Object o6,
                                     java.lang.Object o7)
        Verify arguments.
        Throws:
        java.lang.IllegalArgumentException - If o1 == null || o2 == null || o3 == null || o4 == null || o5 == null || o6 == null || o7 == null.
        Since:
        5.9
      • assertTrue

        public static void assertTrue​(java.lang.String message,
                                      boolean condition)
        Asserts that a condition is true.

        Throws:
        AssertException - If condition is false
      • assertTrue

        public static void assertTrue​(boolean condition)
        Asserts that a condition is true.

        Throws:
        AssertException - If condition is false
      • assertEquals

        public static void assertEquals​(double expected,
                                        double actual,
                                        double delta)
        Asserts that two doubles are equal.
        Parameters:
        expected - the expected value of an object
        actual - the actual value of an object
        delta - tolerated delta
        Throws:
        AssertException - If assert is not fulfilled
      • assertEquals

        public static void assertEquals​(long expected,
                                        long actual)
        Asserts that two longs are equal.
        Parameters:
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • assertEquals

        public static void assertEquals​(java.lang.Object expected,
                                        java.lang.Object actual)
        Asserts that two objects are equal.

        Parameters:
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • assertEquals

        public static void assertEquals​(java.lang.String message,
                                        double expected,
                                        double actual,
                                        double delta)
        Asserts that two doubles are equal.
        Parameters:
        message - the detail message for this assertion
        expected - the expected value of an object
        actual - the actual value of an object
        delta - tolerated delta
        Throws:
        AssertException - If assert is not fulfilled
      • assertEquals

        public static void assertEquals​(java.lang.String message,
                                        long expected,
                                        long actual)
        Asserts that two longs are equal.
        Parameters:
        message - the detail message for this assertion
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • assertEquals

        public static void assertEquals​(java.lang.String message,
                                        java.lang.Object expected,
                                        java.lang.Object actual)
        Asserts that two objects are equal. If they are not an AssertionFailedError is thrown.
        Parameters:
        message - the detail message for this assertion
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • assertNotNull

        public static void assertNotNull​(java.lang.Object object)
        Asserts that an object isn't null.
        Throws:
        AssertException - If assert is not fulfilled
      • assertNotNull

        public static void assertNotNull​(java.lang.String message,
                                         java.lang.Object object)
        Asserts that an object isn't null.
        Throws:
        AssertException - If assert is not fulfilled
      • assertNull

        public static void assertNull​(java.lang.Object object)
        Asserts that an object is null.
        Throws:
        AssertException - If assert is not fulfilled
      • assertNull

        public static void assertNull​(java.lang.String message,
                                      java.lang.Object object)
        Asserts that an object is null.
        Throws:
        AssertException - If assert is not fulfilled
      • assertSame

        public static void assertSame​(java.lang.Object expected,
                                      java.lang.Object actual)
        Asserts that two objects refer to the same object.

        Parameters:
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • assertSame

        public static void assertSame​(java.lang.String message,
                                      java.lang.Object expected,
                                      java.lang.Object actual)
        Asserts that two objects refer to the same object.

        Parameters:
        message - the detail message for this assertion
        expected - the expected value of an object
        actual - the actual value of an object
        Throws:
        AssertException - If assert is not fulfilled
      • fail

        public static final void fail()
        Throws a AssertException and print the trace.

      • fail

        public static final void fail​(java.lang.String message)
        Throws a AssertException and print the trace.