Class Asserters

java.lang.Object
org.testframe.api.Asserters

public class Asserters extends Object
Static class containing procedures to simplify writing assertions in tests. It almost goes without saying that each of these throws an AssertionError if the specified assertion fails. That particular bit of information is not repeated in any procedure's Javadoc, but I do try to make a note of other throwables that might arise even if they seem obvious (e.g., NullPointerException).

The following assertions will not be provided:

  • No assertArrayEquals() will be provided. Just use assertEquals() — same as in TestNG.
  • Neither assertTrue nor assertFalse will be provided. Use plain Java assert.
  • No assertNotNull() will be provided. Use plain Java assert.
Since:
1.0
Author:
Alonso del Arte
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    The default tolerance for comparing floating point values, roughly 1.52587890625 × 10−5.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <E> void
    assertContains(E expected, E[] actual)
    Asserts the array contains the specified element.
    static <E> void
    assertContains(E expected, E[] actual, String msg)
    Asserts that an array contains a specified element.
    static <E> void
    assertContains(E expected, List<E> actual)
    Asserts that a list contains a specified element.
    static <E> void
    assertContains(E expected, List<E> actual, String msg)
    Asserts that a list contains a specified element.
    static <E> void
    assertContains(E expected, Set<E> actual)
    Asserts that a set contains a specified element.
    static <E> void
    assertContains(E expected, Set<E> actual, String msg)
    Asserts that a set contains a specified element.
    static <E> void
    assertContainsSame(E[] expected, E[] actual)
    Asserts that two arrays contain the same elements, though not necessarily in the same order or the same quantities.
    static <E> void
    assertContainsSame(E[] expected, E[] actual, String msg)
    Asserts that two arrays contain the same elements, though not necessarily in the same order or the same quantities.
    static <E> void
    assertContainsSame(List<E> expected, List<E> actual)
    Asserts that two lists contain the same elements, though not necessarily in the same order or the same quantities.
    static <E> void
    assertContainsSame(List<E> expected, List<E> actual, String msg)
    Asserts that two lists contain the same elements, though not necessarily in the same order or the same quantities.
    static <E> void
    assertContainsSame(Set<E> expected, Set<E> actual)
    Asserts that two sets contain the same elements.
    static <E> void
    assertContainsSame(Set<E> expected, Set<E> actual, String msg)
    Asserts that two sets contain the same elements.
    static <E> void
    assertContainsSameOrder(List<E> expected, List<E> actual)
    Asserts two lists contain the same elements in the same order.
    static <E> void
    assertContainsSameOrder(List<E> expected, List<E> actual, String msg)
    Asserts two lists contain the same elements in the same order.
    static void
    assertDifferent(double[] some, double[] other)
    Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than DEFAULT_TEST_DELTA.
    static void
    assertDifferent(double[] some, double[] other, double delta)
    Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than a specified variance.
    static void
    assertDifferent(double[] some, double[] other, double delta, String msg)
    Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than a specified variance.
    static void
    assertDifferent(double[] some, double[] other, String msg)
    Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than DEFAULT_TEST_DELTA.
    static void
    assertDifferent(double some, double other)
    Asserts that a floating point value is different from some floating point value by more than DEFAULT_TEST_DELTA.
    static void
    assertDifferent(double some, double other, double delta)
    Asserts that a floating point value is different from some floating point value by more than a specified variance.
    static void
    assertDifferent(double some, double other, double delta, String msg)
    Asserts that a floating point value is different from some floating point value by more than a specified variance.
    static void
    assertDifferent(double some, double other, String msg)
    Asserts that a floating point value is different from some floating point value by more than DEFAULT_TEST_DELTA.
    static void
    assertDifferent(int[] some, int[] other)
    Asserts that two arrays of integers are different, in at least one of the elements if not in length.
    static void
    assertDifferent(int[] some, int[] other, String msg)
    Asserts that two arrays of integers are different, in at least one of the elements if not in length.
    static void
    assertDifferent(long some, long other)
    Asserts that an integer value is different from some other integer value.
    static void
    assertDifferent(long some, long other, String msg)
    Asserts that an integer value is different from some other integer value.
    static <E> void
    assertDifferent(E[] some, E[] other)
    Asserts that two arrays of objects are different in some way, such as that they contain different elements, contain the same elements in a different order, or differ in length.
    static <E> void
    assertDifferent(E[] some, E[] other, String msg)
    Asserts that two arrays of objects are different in some way, such as that they contain different elements, contain the same elements in a different order, or differ in length.
    static void
    Asserts that two objects are different.
    static void
    assertDifferent(Object some, Object other, String msg)
    Asserts that two objects are different.
    static void
    Asserts that a given lambda does not throw exceptions of any type.
    static void
    Asserts that a given lambda does not throw exceptions of any type.
    static void
    assertEquals(double[] expected, double[] actual)
    Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within DEFAULT_TEST_DELTA.
    static void
    assertEquals(double[] expected, double[] actual, double delta)
    Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within a specified variance.
    static void
    assertEquals(double[] expected, double[] actual, double delta, String msg)
    Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within a specified variance.
    static void
    assertEquals(double[] expected, double[] actual, String msg)
    Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within DEFAULT_TEST_DELTA.
    static void
    assertEquals(double expected, double actual)
    Asserts that two floating point numbers are equal, or very close to equal, according to the default variance, DEFAULT_TEST_DELTA.
    static void
    assertEquals(double expected, double actual, double delta)
    Asserts that two floating point numbers are equal, or very close to equal, according to a specified variance.
    static void
    assertEquals(double expected, double actual, double delta, String msg)
    Asserts that two floating point numbers are equal, or very close to equal, according to a specified variance.
    static void
    assertEquals(double expected, double actual, String msg)
    Asserts that two floating point numbers are equal, or very close to equal, according to the default variance, DEFAULT_TEST_DELTA.
    static void
    assertEquals(int[] expected, int[] actual)
    Asserts the two arrays of integers are of the same length and contain the same numbers.
    static void
    assertEquals(int[] expected, int[] actual, String msg)
    Asserts the two arrays of integers are of the same length and contain the same numbers.
    static void
    assertEquals(int expected, int actual)
    Asserts that two integers are equal.
    static void
    assertEquals(int expected, int actual, String msg)
    Asserts that two integers are equal.
    static void
    assertEquals(long expected, long actual)
    Asserts that two integers are equal.
    static void
    assertEquals(long expected, long actual, String msg)
    Asserts that two integers are equal.
    static void
    assertEquals(Object[] expected, Object[] actual)
    Asserts that two arrays of Object instances are equal.
    static void
    assertEquals(Object[] expected, Object[] actual, String msg)
    Asserts that two arrays of Object instances are equal.
    static void
    assertEquals(Object expected, Object actual)
    Asserts that two objects are equal according to the pertinent equals() function.
    static void
    assertEquals(Object expected, Object actual, String msg)
    Asserts that two objects are equal according to the pertinent equals() function.
    static void
    assertInRange(double minimum, double actual, double maximum)
    Asserts that a floating point number is in a given range.
    static void
    assertInRange(double minimum, double actual, double maximum, double delta)
    Asserts that a floating point number is in a given range.
    static void
    assertInRange(double minimum, double actual, double maximum, double delta, String msg)
    Asserts that a floating point number is in a given range.
    static void
    assertInRange(double minimum, double actual, double maximum, String msg)
    Asserts that a floating point number is in a given range.
    static void
    assertInRange(long minimum, long actual, long maximum)
    Asserts that an integer is in a given range.
    static void
    assertInRange(long minimum, long actual, long maximum, String msg)
    Asserts that an integer is in a given range.
    static <T extends Comparable<T>>
    void
    assertInRange(T minimum, T actual, T maximum)
    Asserts that an object is in a given range.
    static <T extends Comparable<T>>
    void
    assertInRange(T minimum, T actual, T maximum, String msg)
    Asserts that an object is in a given range.
    static void
    assertMaximum(double actual, double maximum)
    Asserts a floating point number is less than or equal to a specified maximum.
    static void
    assertMaximum(double actual, double maximum, String msg)
    Asserts a floating point number is less than or equal to a specified maximum.
    static void
    assertMaximum(long actual, long maximum)
    Asserts an integer is not greater than a specified maximum.
    static void
    assertMaximum(long actual, long maximum, String msg)
    Asserts an integer is not greater than a specified maximum.
    static <T extends Comparable<T>>
    void
    assertMaximum(T actual, T maximum)
    Asserts that the value held by a Comparable object is less than or equal to a specified maximum.
    static <T extends Comparable<T>>
    void
    assertMaximum(T actual, T maximum, String msg)
    Asserts that the value held by a Comparable object is less than or equal to a specified maximum.
    static void
    assertMinimum(double minimum, double actual)
    Asserts that a floating point number is equal to or greater than a specified minimum.
    static void
    assertMinimum(double minimum, double actual, String msg)
    Asserts that a floating point number is equal to or greater than a specified minimum.
    static void
    assertMinimum(long minimum, long actual)
    Asserts that an integer is greater than or equal to a specified minimum.
    static void
    assertMinimum(long minimum, long actual, String msg)
    Asserts that an integer is greater than or equal to a specified minimum.
    static <T extends Comparable<T>>
    void
    assertMinimum(T minimum, T actual)
    Asserts that the value held by a Comparable object is greater than or equal to a specified minimum.
    static <T extends Comparable<T>>
    void
    assertMinimum(T minimum, T actual, String msg)
    Asserts that the value held by a Comparable object is greater than or equal to a specified minimum.
    static void
    assertNaN(double actual)
    Asserts that a 64-bit floating point number is NaN (not a number).
    static void
    assertNaN(double actual, String msg)
    Asserts that a 64-bit floating point number is NaN (not a number).
    static void
    assertNegative(double actual)
    Asserts that a floating point number is negative.
    static void
    assertNegative(double actual, String msg)
    Asserts that a floating point number is negative.
    static void
    assertNegative(long actual)
    Asserts that an integer is negative.
    static void
    assertNegative(long actual, String msg)
    Asserts that an integer is negative.
    static void
    assertNotNaN(double actual)
    Asserts that a 64-bit floating point number is not NaN (not a number).
    static void
    assertNotNaN(double actual, String msg)
    Asserts that a 64-bit floating point number is not NaN (not a number).
    static void
    assertNotNegative(double actual)
    Asserts a given number is not negative.
    static void
    assertNotNegative(double actual, String msg)
    Asserts a given number is not negative.
    static void
    assertNotNegative(long actual)
    Asserts a given number is not negative.
    static void
    assertNotNegative(long actual, String msg)
    Asserts a given number is not negative.
    static void
    assertNotPositive(double actual)
    Asserts a given number is not positive.
    static void
    assertNotPositive(double actual, String msg)
    Asserts a given number is not positive.
    static void
    assertNotPositive(long actual)
    Asserts that an integer is not positive.
    static void
    assertNotPositive(long actual, String msg)
    Asserts that an integer is not positive.
    static void
    Asserts that an object is null.
    static void
    assertNull(Object object, String msg)
    Asserts that an object is null.
    static void
    assertPositive(double actual)
    Asserts that a floating point number is positive.
    static void
    assertPositive(double actual, String msg)
    Asserts that a floating point number is positive.
    static void
    assertPositive(long actual)
    Asserts that an integer is positive.
    static void
    assertPositive(long actual, String msg)
    Asserts that an integer is positive.
    static String
    assertPrintOut(Predicate<String> predicate, Procedure lambda, String msg)
    Makes a Boolean assertion about what a lambda sends to System.out.
    static <E extends Exception>
    E
    assertThrows(Procedure lambda, Class<E> exceptionType)
    Asserts that a given lambda caused an exception of a particular type.
    static <E extends Exception>
    E
    assertThrows(Procedure lambda, Class<E> exceptionType, String msg)
    Asserts that a given lambda caused an exception of a particular type.
    static void
    assertTimeout(Procedure lambda, Duration allottedTime, String msg)
    Asserts that a lambda completes in a certain amount of time.
    static void
    assertZero(double actual)
    Asserts that a 64-bit floating point number is equal to 0.0 (or to −0.0).
    static void
    assertZero(double actual, String msg)
    Asserts that a 64-bit floating point number is equal to 0.0 (or to −0.0).
    static void
    assertZero(long actual)
    Asserts that an integer is equal to zero.
    static void
    assertZero(long actual, String msg)
    Asserts that an integer is equal to zero.
    static void
    fail(String msg)
    Fails a test regardless of anything else.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_TEST_DELTA

      public static final double DEFAULT_TEST_DELTA
      The default tolerance for comparing floating point values, roughly 1.52587890625 × 10−5. This might be too little for most purposes, but it's better than 0.0 or any subnormal value.
      See Also:
  • Method Details

    • assertEquals

      public static void assertEquals(int expected, int actual)
      Asserts that two integers are equal. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail. The test failure explanation will state what the expected value was and what the actual value was.
      Parameters:
      expected - The expected integer. For example, 73.
      actual - The actual integer. For example, −410.
    • assertEquals

      public static void assertEquals(int expected, int actual, String msg)
      Asserts that two integers are equal. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail.
      Parameters:
      expected - The expected integer. For example, −489.
      actual - The actual integer. For example, 22050.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "The two lists have the same elements and should therefore they should be the same size." The expected and actual values will be appended to the test failure explanation.
    • assertEquals

      public static void assertEquals(long expected, long actual)
      Asserts that two integers are equal. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail. The test failure explanation will state what the expected value was and what the actual value was.
      Parameters:
      expected - The expected integer. For example, 4294967369.
      actual - The actual integer. For example, −4294967779.
    • assertEquals

      public static void assertEquals(long expected, long actual, String msg)
      Asserts that two integers are equal. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail.
      Parameters:
      expected - The expected integer. For example, −4294968268.
      actual - The actual integer. For example, 4294990318.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "The two lists have the same elements and should therefore they should be the same size." The expected and actual values will be appended to the test failure explanation.
    • assertEquals

      public static void assertEquals(double expected, double actual)
      Asserts that two floating point numbers are equal, or very close to equal, according to the default variance, DEFAULT_TEST_DELTA. A default message specifying the expected, actual and variance values will be given if the expected and actual values diverge by more than the default variance.

      Note however that the test will fail if both of the floating point values are NaN, regardless of their bit patterns.

      Parameters:
      expected - The expected value. For example, 3.14159.
      actual - The actual value. For example, 3.14161.
    • assertEquals

      public static void assertEquals(double expected, double actual, double delta)
      Asserts that two floating point numbers are equal, or very close to equal, according to a specified variance. A default message specifying the expected, actual and variance values will be given if the expected and actual values diverge by more than the allowed variance.

      Note however that the test will fail if both of the floating point values are NaN, regardless of their bit patterns.

      Parameters:
      expected - The expected value. For example, 3.14159.
      actual - The actual value. For example, 3.14161.
      delta - The maximum allowed variance for expected and actual to differ and still be considered close enough to be equal. For example, 0.00001. Ought to be at least 0.0 but is preferably positive, though less than 1.0. Negative variances are not recommended, and the behavior is not at all guaranteed to remain consistent from one version of this framework to the next.
    • assertEquals

      public static void assertEquals(double expected, double actual, String msg)
      Asserts that two floating point numbers are equal, or very close to equal, according to the default variance, DEFAULT_TEST_DELTA.

      Note however that the test will fail if both of the floating point values are NaN, regardless of their bit patterns.

      Parameters:
      expected - The expected value. For example, 3.14159.
      actual - The actual value. For example, 3.14161.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "The number should converge to π." The expected, actual and default delta values will be appended to the test failure explanation.
    • assertEquals

      public static void assertEquals(double expected, double actual, double delta, String msg)
      Asserts that two floating point numbers are equal, or very close to equal, according to a specified variance.

      Note however that the test will fail if both of the floating point values are NaN, regardless of their bit patterns.

      Parameters:
      expected - The expected value. For example, 3.14159.
      actual - The actual value. For example, 3.14161.
      delta - The maximum allowed variance for expected and actual to differ and still be considered close enough to be equal. For example, 0.00001. Ought to be at least 0.0 but is preferably positive, though less than 1.0. Negative variances are not recommended, and the behavior is not at all guaranteed to remain consistent from one version of this framework to the next.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "The number should converge to π." The expected, actual and delta values will be appended to the test failure explanation.
    • assertEquals

      public static void assertEquals(Object expected, Object actual)
      Asserts that two objects are equal according to the pertinent equals() function. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail. The test failure explanation will state what the expected value was and what the actual value was.
      Parameters:
      expected - The expected object. For example, a LocalDateTime object for right now. Note that it is this parameter's equals() function that will be called.
      actual - The actual object. For example, a LocalDateTime object for this time of day tomorrow.
      Throws:
      NullPointerException - If expected is null.
    • assertEquals

      public static void assertEquals(Object expected, Object actual, String msg)
      Asserts that two objects are equal according to the pertinent equals() function. If they are indeed equal and there are no other assertions in the test, the test should pass. But if they are not equal, the test should fail. The test failure explanation will state what the expected value was and what the actual value was.
      Parameters:
      expected - The expected object. For example, a LocalDateTime object for right now. Note that it is this parameter's equals() function that will be called.
      actual - The actual object. For example, a LocalDateTime object for this time of day tomorrow.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "Transaction date of withdrawal from account A should match date of deposit to account B." The expected and actual values will be appended to the test failure explanation.
      Throws:
      NullPointerException - If expected is null.
    • assertEquals

      public static void assertEquals(int[] expected, int[] actual)
      Asserts the two arrays of integers are of the same length and contain the same numbers. The contents of the arrays will be compared only if the arrays match in length. The test failure explanation will either state that the arrays differ in length or at what index the first difference was encountered if they do match in length.
      Parameters:
      expected - The expected array. For example, {1, 3, 4, 7, 11, 18, 29, 47, 76}.
      actual - The actual array. Examples: {2, 1, 3, 4, 7, 11, 18, 29, 47, 76}, {1, 3, 4, 7, 11, 12, 18, 21, 28}.
    • assertEquals

      public static void assertEquals(int[] expected, int[] actual, String msg)
      Asserts the two arrays of integers are of the same length and contain the same numbers. The contents of the arrays will be compared only if the arrays match in length.
      Parameters:
      expected - The expected array. For example, {1, 3, 4, 7, 11, 18, 29, 47, 76}.
      actual - The actual array. Examples: {2, 1, 3, 4, 7, 11, 18, 29, 47, 76}, {1, 3, 4, 7, 11, 12, 18, 21, 28}.
      msg - A message for the test failure explanation.
    • assertEquals

      public static void assertEquals(double[] expected, double[] actual)
      Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within DEFAULT_TEST_DELTA. This procedure stops at the first evidence of failure. First, it checks that the arrays are of the same length. If they are, it proceeds to compare the numbers index by index, stopping on finding a difference in excess of the variance even if there are more numbers to compare. The test failure explanation will depend on how far along the process came along.

      Note however that the test will fail if both of the floating point values at a given index are NaN, regardless of their bit patterns.

      Parameters:
      expected - The array of expected values. For example, an array containing 4.0, 3.0, 3.25, 3.16 in that order.
      actual - The array of actual values. For example, an array containing 4.0, 3.0, 3.2507, 3.15999 in that order.
    • assertEquals

      public static void assertEquals(double[] expected, double[] actual, double delta)
      Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within a specified variance. This procedure stops at the first evidence of failure. First, it checks that the arrays are of the same length. If they are, it proceeds to compare the numbers index by index, stopping on finding a difference in excess of the variance even if there are more numbers to compare. The test failure explanation will depend on how far along the process came along.

      Note however that the test will fail if both of the floating point values at a given index are NaN, regardless of their bit patterns.

      Parameters:
      expected - The array of expected values. For example, an array containing 4.0, 3.0, 3.25, 3.16 in that order.
      actual - The array of actual values. For example, an array containing 4.0, 3.0, 3.2507, 3.15999 in that order.
      delta - The maximum allowed variance for the numbers in expected and actual to differ and still be considered close enough to be equal. For example, 0.00001. Ought to be at least 0.0 but is preferably positive and not subnormal, though less than 1.0. Negative variances are not recommended, and the behavior is not at all guaranteed to remain consistent from one version of this framework to the next.
    • assertEquals

      public static void assertEquals(double[] expected, double[] actual, String msg)
      Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within DEFAULT_TEST_DELTA. This procedure stops at the first evidence of failure. First, it checks that the arrays are of the same length. If they are, it proceeds to compare the numbers index by index, stopping on finding a difference in excess of the variance even if there are more numbers to compare.

      Note however that the test will fail if both of the floating point values at a given index are NaN, regardless of their bit patterns.

      Parameters:
      expected - The array of expected values. For example, an array containing 4.0, 3.0, 3.25, 3.16 in that order.
      actual - The array of actual values. For example, an array containing 4.0, 3.0, 3.2507, 3.15999 in that order.
      msg - A message to include in the test failure explanation if the assertion fails. For example, "Numbers should converge to π."
    • assertEquals

      public static void assertEquals(double[] expected, double[] actual, double delta, String msg)
      Asserts that two arrays of 64-bit floating point values have the same numbers in the same order within a specified variance. This procedure stops at the first evidence of failure. First, it checks that the arrays are of the same length. If they are, it proceeds to compare the numbers index by index, stopping on finding a difference in excess of the variance even if there are more numbers to compare.

      Note however that the test will fail if both of the floating point values at a given index are NaN, regardless of their bit patterns.

      Parameters:
      expected - The array of expected values. For example, an array containing 4.0, 3.0, 3.25, 3.16 in that order.
      actual - The array of actual values. For example, an array containing 4.0, 3.0, 3.2507, 3.15999 in that order.
      delta - The maximum allowed variance for the numbers in expected and actual to differ and still be considered close enough to be equal. For example, 0.00001. Ought to be at least 0.0 but is preferably positive and not subnormal, though less than 1.0. Negative variances are not recommended, and the behavior is not at all guaranteed to remain consistent from one version of this framework to the next.
      msg - A message to include in the test failure explanation if the assertion fails. For example, "Numbers should converge to π."
    • assertEquals

      public static void assertEquals(Object[] expected, Object[] actual)
      Asserts that two arrays of Object instances are equal. The elements are the same and in the same order. A test failure explanation will be given if the test fails for the arrays being of different lengths or for having a different element.
      Parameters:
      expected - The expected array. For example, the colors cyan, magenta, yellow and black.
      actual - The actual array. For example, the colors cyan, black, yellow and magenta.
    • assertEquals

      public static void assertEquals(Object[] expected, Object[] actual, String msg)
      Asserts that two arrays of Object instances are equal. The elements are the same and in the same order.
      Parameters:
      expected - The expected array. For example, the colors cyan, magenta, yellow and black. Should not contain any nulls.
      actual - The actual array. For example, the colors cyan, black, yellow and magenta.
      msg - A message to include in the test failure explanation if the test fails.
      Throws:
      NullPointerException - If two arrays are of the same length and expected contains even just one null.
    • assertNull

      public static void assertNull(Object object)
      Asserts that an object is null. If the object is not null, the test failure explanation will include the object's toString().

      To assert that an object is not null, use a plain Java assert with an appropriate message.

      Parameters:
      object - The object to assert is null. For example, a field that is not supposed to be initialized at construction time.
    • assertNull

      public static void assertNull(Object object, String msg)
      Asserts that an object is null. To assert that an object is not null, use a plain Java assert with an appropriate message.
      Parameters:
      object - The object to assert is null. For example, a field that is not supposed to be initialized at construction time.
      msg - A message for the test failure explanation, to which will be appended a message saying a null object was expected but instead a non-null object was found, if the test fails.
    • assertMinimum

      public static void assertMinimum(long minimum, long actual)
      Asserts that an integer is greater than or equal to a specified minimum. The test failure explanation will include both the expected minimum and the actual number if it's below the minimum.
      Parameters:
      minimum - The minimum permissible value. For example, 100.
      actual - The value to compare against the specified minimum. For example, 95.
    • assertMinimum

      public static void assertMinimum(long minimum, long actual, String msg)
      Asserts that an integer is greater than or equal to a specified minimum. The test failure explanation will include both the expected minimum and the actual number if it's below the minimum.
      Parameters:
      minimum - The minimum permissible value. For example, 100.
      actual - The value to compare against the specified minimum. For example, 95.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. For example, "List should have at least as many elements as the set." The minimum and actual values will be appended to the test failure explanation.
    • assertMinimum

      public static void assertMinimum(double minimum, double actual)
      Asserts that a floating point number is equal to or greater than a specified minimum. Due to the vagaries of floating point, numbers slightly below the minimum might register as equal to the minimum. The test failure explanation will include both the expected minimum and the actual number if it's below the minimum.
      Parameters:
      minimum - The minimum possible number. For example, −0.5.
      actual - The number to compare against the specified minimum. For example, −1.83.
    • assertMinimum

      public static void assertMinimum(double minimum, double actual, String msg)
      Asserts that a floating point number is equal to or greater than a specified minimum. Due to the vagaries of floating point, numbers slightly below the minimum might register as equal to the minimum. The test failure explanation will include both the expected minimum and the actual number if it's below the minimum.
      Parameters:
      minimum - The minimum possible number. For example, −0.5.
      actual - The number to compare against the specified minimum. For example, −1.83.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The minimum and actual values will be appended to the test failure explanation.
    • assertMinimum

      public static <T extends Comparable<T>> void assertMinimum(T minimum, T actual)
      Asserts that the value held by a Comparable object is greater than or equal to a specified minimum.
      Type Parameters:
      T - The type of the minimum and actual parameters. Must implement Comparable<T>. For example, Fraction implements Comparable<Fraction>.
      Parameters:
      minimum - The minimum permissible value. For example, 32.
      actual - The value to compare against the specified minimum. For example, 2116.
    • assertMinimum

      public static <T extends Comparable<T>> void assertMinimum(T minimum, T actual, String msg)
      Asserts that the value held by a Comparable object is greater than or equal to a specified minimum.
      Type Parameters:
      T - The type of the minimum and actual parameters. Must implement Comparable<T>. For example, Fraction implements Comparable<Fraction>.
      Parameters:
      minimum - The minimum permissible value. For example, 32.
      actual - The value to compare against the specified minimum. For example, 2116.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The minimum and actual values will be appended to the test failure explanation.
    • assertNegative

      public static void assertNegative(long actual)
      Asserts that an integer is negative. The actual number and the maximum −1 will be included in the test failure explanation if the assertion fails.
      Parameters:
      actual - The number to check. For example, −14370899.
    • assertNegative

      public static void assertNegative(long actual, String msg)
      Asserts that an integer is negative.
      Parameters:
      actual - The number to check. For example, −14370899.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The number actual and the maximum −1 will be appended to the test failure explanation.
    • assertNegative

      public static void assertNegative(double actual)
      Asserts that a floating point number is negative. However, due to the vagaries of floating point, negative subnormal numbers might be erroneously regarded as not negative.

      Other special cases to be aware of:

      • Negative infinity should not fail the assertion, same as finite negative numbers.
      • Negative zero, an oddity of the floating point specification, should nevertheless be considered not negative.
      • Positive zero should of course fail the assertion, the same as positive numbers.
      • Positive infinity should fail the assertion, same as finite positive numbers.
      • NaN should fail the assertion even if the bit pattern is negative. And in any case, it's difficult to access NaN values other than the "canonical" NaN through the Java Virtual Machine.

      If the test fails, the test failure explanation will include the number actual and the threshold 0.0, except in the case of asserting on NaN, in which case the test failure explanation will state that NaN is not considered negative, zero or positive.

      Parameters:
      actual - The number to check. For example, −2.6065827580858707 × 108.
    • assertNegative

      public static void assertNegative(double actual, String msg)
      Asserts that a floating point number is negative. However, due to the vagaries of floating point, negative subnormal numbers might be erroneously regarded as not negative.

      Other special cases to be aware of:

      • Negative infinity should not fail the assertion, same as finite negative numbers.
      • Negative zero, an oddity of the floating point specification, should nevertheless be considered not negative.
      • Positive zero should of course fail the assertion, the same as positive numbers.
      • Positive infinity should fail the assertion, same as finite positive numbers.
      • NaN should fail the assertion even if the bit pattern is negative. And in any case, it's difficult to access NaN values other than the "canonical" NaN through the Java Virtual Machine.
      Parameters:
      actual - The number to check. For example, −2.6065827580858707 × 108.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The number actual and the threshold 0.0 will be appended to the test failure explanation, or, in the case of NaN, the appended explanation will say that NaN "is not considered negative, zero or positive."
    • assertNotPositive

      public static void assertNotPositive(long actual)
      Asserts that an integer is not positive. Remember that 0 is not positive. If the test fails because of the assertion, the number actual and the threshold 1 will be appended to the test failure explanation.
      Parameters:
      actual - The number to assert is not positive. For example, −47.
    • assertNotPositive

      public static void assertNotPositive(long actual, String msg)
      Asserts that an integer is not positive. Remember that 0 is not positive.
      Parameters:
      actual - The number to assert is not positive. For example, −47.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The number actual and the threshold 1 will be appended to the test failure explanation.
    • assertNotPositive

      public static void assertNotPositive(double actual)
      Asserts a given number is not positive. The number may be −0.0 or 0.0 without failing the assertion. It may also be NaN and not fail the assertion (remember that NaN is neither positive nor negative even though the bit pattern may be negative, zero or positive), and obviously −∞ won't either. However, +∞ will fail the assertion.
      Parameters:
      actual - The number to be checked. For example, 10.843979291045144. This number will be included in the test failure explanation if the test fails because of this assertion.
    • assertNotPositive

      public static void assertNotPositive(double actual, String msg)
      Asserts a given number is not positive. The number may be −0.0 or 0.0 without failing the assertion. It may also be NaN and not fail the assertion (remember that NaN is neither positive nor negative even though the bit pattern may be negative, zero or positive), and obviously −∞ won't either. However, +∞ will fail the assertion.
      Parameters:
      actual - The number to be checked. For example, 10.843979291045144.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The actual value will be included in the test failure explanation.
    • assertZero

      public static void assertZero(long actual)
      Asserts that an integer is equal to zero. This has the same effect as an assertEquals() with 0 as the expected value, though the test failure messages might differ in their wording. The number actual number and the expected value of 0 will be appended to the test failure explanation.
      Parameters:
      actual - The number to assert is equal to 0. For example, 133.
    • assertZero

      public static void assertZero(long actual, String msg)
      Asserts that an integer is equal to zero. This has the same effect as an assertEquals() with 0 as the expected value, though the test failure messages might differ in their wording.
      Parameters:
      actual - The number to assert is equal to 0. For example, 133.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The number actual and the expected value of 0 will be appended to the test failure explanation.
    • assertZero

      public static void assertZero(double actual)
      Asserts that a 64-bit floating point number is equal to 0.0 (or to −0.0). However, if a nonzero subnormal number is acceptable to pass the test, then use assertEquals(double, double, double) with a small delta or assertEquals(double, double) which uses DEFAULT_TEST_DELTA as the delta instead. The default test failure explanation will include the numbers actual and 0.0.
      Parameters:
      actual - The floating point number to assert is equal to ±0.0. For example, −0.0078125.
    • assertZero

      public static void assertZero(double actual, String msg)
      Asserts that a 64-bit floating point number is equal to 0.0 (or to −0.0). However, if a nonzero subnormal number is acceptable to pass the test, then use assertEquals(double, double, double, String) with a small delta or assertEquals(double, double, String) which uses DEFAULT_TEST_DELTA as the delta instead.
      Parameters:
      actual - The floating point number to assert is equal to ±0.0. For example, −0.0078125.
      msg - The message for the test failure explanation. The numbers actual and 0.0 will be appended to this message.
    • assertNotNegative

      public static void assertNotNegative(long actual)
      Asserts a given number is not negative. The number may be 0 without failing the assertion. The number will be included in the test failure explanation if the test fails because of this assertion.
      Parameters:
      actual - The number to be checked. For example, −103.
    • assertNotNegative

      public static void assertNotNegative(long actual, String msg)
      Asserts a given number is not negative. The number may be 0 without failing the assertion.
      Parameters:
      actual - The number to be checked. For example, −103.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The actual value will be appended to the test failure explanation.
    • assertNotNegative

      public static void assertNotNegative(double actual)
      Asserts a given number is not negative. The number may be -0.0 or 0.0 without failing the assertion.
      Parameters:
      actual - The number to be checked. For example, 10.843979291045144.
    • assertNotNegative

      public static void assertNotNegative(double actual, String msg)
      Asserts a given number is not negative. The number may be −0.0 or 0.0 without failing the assertion. Note that a NaN value is considered not negative even if its bit pattern is negative.
      Parameters:
      actual - The number to be checked. For example, 10.843979291045144.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The actual value will be included in the test failure explanation.
    • assertPositive

      public static void assertPositive(long actual)
      Asserts that an integer is positive. The number must be 1 or greater to pass the assertion.
      Parameters:
      actual - The number to assert is positive. For example, −347.
    • assertPositive

      public static void assertPositive(long actual, String msg)
      Asserts that an integer is positive. The number must be 1 or greater to pass the assertion.
      Parameters:
      actual - The number to assert is positive. For example, −347.
      msg - The message for the test failure explanation.
    • assertPositive

      public static void assertPositive(double actual)
      Asserts that a floating point number is positive. If the test fails, the actual number and the threshold 0.0 will be included in the test failure explanation, or, in the case of NaN, the explanation will say that NaN "is not considered negative, zero or positive."

      Due to the vagaries of floating point, positive subnormal numbers might be erroneously regarded as not positive.

      Other special cases to be aware of:

      • Positive infinity should not fail the assertion, same as most finite positive numbers.
      • Negative zero, an oddity of the floating point specification, should nevertheless be considered not positive.
      • Positive zero should of course fail the assertion.
      • Negative infinity should fail the assertion, same as finite negative numbers.
      Parameters:
      actual - The number to check. For example, −2.6065827580858707 × 108.
    • assertPositive

      public static void assertPositive(double actual, String msg)
      Asserts that a floating point number is positive. However, due to the vagaries of floating point, positive subnormal numbers might be erroneously regarded as not positive.

      Other special cases to be aware of:

      • Positive infinity should not fail the assertion, same as most finite positive numbers.
      • Negative zero, an oddity of the floating point specification, should nevertheless be considered not positive.
      • Positive zero should of course fail the assertion.
      • Negative infinity should fail the assertion, same as finite negative numbers.
      • NaN should fail the assertion even if the bit pattern is positive. And in any case, it's difficult to access NaN values other than the "canonical" NaN through the Java Virtual Machine.
      Parameters:
      actual - The number to check. For example, −2.6065827580858707 × 108.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The number actual and the threshold 0.0 will be appended to the test failure explanation, or, in the case of NaN, the appended explanation will say that NaN "is not considered negative, zero or positive."
    • assertMaximum

      public static void assertMaximum(long actual, long maximum)
      Asserts an integer is not greater than a specified maximum. The test failure explanation will include the expected maximum and the actual value if the assertion fails.
      Parameters:
      actual - The number to test for not going over the maximum. For example, 1000.
      maximum - The maximum that actual can be without failing the assertion. For example, 973.
    • assertMaximum

      public static void assertMaximum(long actual, long maximum, String msg)
      Asserts an integer is not greater than a specified maximum.
      Parameters:
      actual - The number to test for not going over the maximum. For example, 1000.
      maximum - The maximum that actual can be without failing the assertion. For example, 973.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertMaximum

      public static void assertMaximum(double actual, double maximum)
      Asserts a floating point number is less than or equal to a specified maximum. The maximum and the actual number will be included in the test failure explanation if the assertion fails.
      Parameters:
      actual - The number to assert is less than a given maximum. For example, 99.890773.
      maximum - The number actual is expected to be less than or equal to. For example, 100.0.
    • assertMaximum

      public static void assertMaximum(double actual, double maximum, String msg)
      Asserts a floating point number is less than or equal to a specified maximum.
      Parameters:
      actual - The number to assert is less than a given maximum. For example, 99.890773.
      maximum - The number actual is expected to be less than or equal to. For example, 100.0.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertMaximum

      public static <T extends Comparable<T>> void assertMaximum(T actual, T maximum)
      Asserts that the value held by a Comparable object is less than or equal to a specified maximum. The test failure explanation will include the actual value and the maximum if the assertion fails.
      Type Parameters:
      T - The type of the maximum and actual parameters. Must implement Comparable<T>. For example, Fraction implements Comparable<Fraction>.
      Parameters:
      actual - The value to compare against the specified maximum. For example, 2516.
      maximum - The maximum permissible value. For example, 32.
    • assertMaximum

      public static <T extends Comparable<T>> void assertMaximum(T actual, T maximum, String msg)
      Asserts that the value held by a Comparable object is less than or equal to a specified maximum.
      Type Parameters:
      T - The type of the maximum and actual parameters. Must implement Comparable<T>. For example, Fraction implements Comparable<Fraction>.
      Parameters:
      actual - The value to compare against the specified maximum. For example, 2516.
      maximum - The maximum permissible value. For example, 32.
      msg - The message to put into the test failure explanation if the test fails because of the assertion. The maximum and actual values will be appended to the test failure explanation.
    • assertNaN

      public static void assertNaN(double actual)
      Asserts that a 64-bit floating point number is NaN (not a number). Don't use assertEquals() because NaN is never equal to itself. The test failure explanation will include NaN and the actual number if the test fails.
      Parameters:
      actual - The number to assert is NaN. For example, negative infinity.
    • assertNaN

      public static void assertNaN(double actual, String msg)
      Asserts that a 64-bit floating point number is NaN (not a number). Note that if the number to be checked is indeed NaN, it will almost certainly be the "canonical" NaN. Don't use assertEquals() because no NaN is ever equal to itself, not even canonical NaN.
      Parameters:
      actual - The number to assert is NaN. For example, positive infinity.
      msg - The message to put into the test failure explanation if the test fails because of the assertion.
    • assertNotNaN

      public static void assertNotNaN(double actual)
      Asserts that a 64-bit floating point number is not NaN (not a number). The test failure explanation will state that the number is expected to not be NaN.
      Parameters:
      actual - The number to assert is not NaN. For example, Math.PI.
    • assertNotNaN

      public static void assertNotNaN(double actual, String msg)
      Asserts that a 64-bit floating point number is not NaN (not a number).
      Parameters:
      actual - The number to assert is not NaN. For example, Math.PI.
      msg - The message to be included in the test failure explanation if the number is indeed NaN.
    • assertInRange

      public static void assertInRange(long minimum, long actual, long maximum)
      Asserts that an integer is in a given range. Using this assertion is similar to combining assertMinimum(long, long) and assertMaximum(long, long) in a single test, but with this assertion, if the assertion fails, the test failure explanation will include both the minimum and the maximum regardless of whether or not the failure was for the actual number being too low or too high.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −163. If this parameter is 0 or 1 and maximum is Long.MAX_VALUE, then it might be better to use assertNotNegative(long) or assertPositive(long) instead. This parameter may be equal to maximum, but must not be greater.
      actual - The number said to be between minimum and maximum. For example, −1. This number may be equal to either minimum or maximum and still not cause the assertion to fail.
      maximum - The highest number that actual can be without failing the test. For example, 73. This parameter is allowed to be equal to minimum, but generally it makes more sense to use assertEquals(long, long) in that case. This parameter must not be less than minimum.
      Throws:
      IllegalArgumentException - If minimum is greater than maximum, without regard for what actual is. The exception message will include minimum and maximum but not actual.
    • assertInRange

      public static void assertInRange(long minimum, long actual, long maximum, String msg)
      Asserts that an integer is in a given range. Using this assertion is similar to combining assertMinimum(long, long, String) and assertMaximum(long, long, String) in a single test, but with this assertion, if the assertion fails, the test failure explanation will include both the minimum and the maximum regardless of whether or not the failure was for the actual number being too low or too high.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −163. If this parameter is 0 or 1 and maximum is Long.MAX_VALUE, then it might be better to use assertNotNegative(long, String) or assertPositive(long, String) instead. This parameter may be equal to maximum, but must not be greater.
      actual - The number said to be between minimum and maximum. For example, −1. This number may be equal to either minimum or maximum and still not cause the assertion to fail.
      maximum - The highest number that actual can be without failing the test. For example, 73. This parameter is allowed to be equal to minimum, but generally it makes more sense to use assertEquals(long, long, String) in that case. This parameter must not be less than minimum.
      msg - A message to include in the test failure explanation if the assertion fails.
      Throws:
      IllegalArgumentException - If minimum is greater than maximum, without regard for what actual is. The exception message will include minimum and maximum but not actual.
    • assertInRange

      public static void assertInRange(double minimum, double actual, double maximum)
      Asserts that a floating point number is in a given range. In most cases, the test failure explanation will include the minimum and the maximum.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −0.5. Negative infinity may be used, but in that case it might make more sense to use assertMaximum() instead.
      actual - The actual number. For example, 0.0.
      maximum - The highest number that actual can be without failing the test. For example, 0.5. Positive infinity may be used, but in that case it might make more sense to use assertMinimum() instead.
      Throws:
      IllegalArgumentException - If either minimum or maximum is NaN, or if minimum is greater than maximum, without regard for the variance.
    • assertInRange

      public static void assertInRange(double minimum, double actual, double maximum, double delta)
      Asserts that a floating point number is in a given range. In most cases, the test failure explanation will include the minimum and the maximum.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −0.5. Negative infinity may be used, but in that case it might make more sense to use assertMaximum() instead.
      actual - The actual number. For example, 0.0.
      maximum - The highest number that actual can be without failing the test. For example, 0.5. Positive infinity may be used, but in that case it might make more sense to use assertMinimum() instead.
      delta - How much variance is allowed for actual to be below minimum or above maximum and still pass the test. For example, 0.1.
      Throws:
      IllegalArgumentException - If either minimum or maximum is NaN, or if minimum is greater than maximum, without regard for the variance.
    • assertInRange

      public static void assertInRange(double minimum, double actual, double maximum, String msg)
      Asserts that a floating point number is in a given range. In most cases, the test failure explanation will include the minimum and the maximum. The default variance DEFAULT_TEST_DELTA will be used.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −0.5. Negative infinity may be used, but in that case it might make more sense to use assertMaximum() instead.
      actual - The actual number. For example, 0.0.
      maximum - The highest number that actual can be without failing the test. For example, 0.5. Positive infinity may be used, but in that case it might make more sense to use assertMinimum() instead.
      msg - A message to include in the test failure explanation.
      Throws:
      IllegalArgumentException - If either minimum or maximum is NaN, or if minimum is greater than maximum, without regard for the variance.
    • assertInRange

      public static void assertInRange(double minimum, double actual, double maximum, double delta, String msg)
      Asserts that a floating point number is in a given range. In most cases, the test failure explanation will include the minimum and the maximum.
      Parameters:
      minimum - The lowest number that actual can be without failing the test. For example, −0.5. Negative infinity may be used, but in that case it might make more sense to use assertMaximum() instead.
      actual - The actual number. For example, 0.0.
      maximum - The highest number that actual can be without failing the test. For example, 0.5. Positive infinity may be used, but in that case it might make more sense to use assertMinimum() instead.
      delta - How much variance is allowed for actual to be below minimum or above maximum and still pass the test. For example, 0.1.
      msg - A message to include in the test failure explanation.
      Throws:
      IllegalArgumentException - If either minimum or maximum is NaN, or if minimum is greater than maximum, without regard for the variance.
    • assertInRange

      public static <T extends Comparable<T>> void assertInRange(T minimum, T actual, T maximum)
      Asserts that an object is in a given range. Using this assertion is similar to combining assertMinimum(Comparable, Comparable) and assertMaximum(Comparable, Comparable) in a single test. But if this assertion fails, the test failure explanation will include both the minimum and the maximum, regardless of whether it's because the actual value was too low or too high. The actual value will be included as well.
      Type Parameters:
      T - The type for minimum, actual and maximum. Must implement Comparable<T>. For example, DayOfWeek.
      Parameters:
      minimum - The lowest value actual can be and still pass the assertion. For example, Monday.
      actual - The actual value. For example, Tuesday.
      maximum - The highest value actual can be and still pass the assertion. For example, Friday.
      Throws:
      IllegalArgumentException - If minimum is greater than maximum.
    • assertInRange

      public static <T extends Comparable<T>> void assertInRange(T minimum, T actual, T maximum, String msg)
      Asserts that an object is in a given range. Using this assertion is similar to combining assertMinimum(Comparable, Comparable, String) and assertMaximum(Comparable, Comparable, String) in a single test. But if this assertion fails, the test failure explanation will include both the minimum and the maximum, regardless of whether it's because the actual value was too low or too high. The actual value will be included as well.
      Type Parameters:
      T - The type for minimum, actual and maximum. Must implement Comparable<T>. For example, DayOfWeek.
      Parameters:
      minimum - The lowest value actual can be and still pass the assertion. For example, Monday.
      actual - The actual value. For example, Tuesday.
      maximum - The highest value actual can be and still pass the assertion. For example, Friday.
      msg - A message to include in the test failure explanation if the assertion fails. For example, "Assigned day expected to be a weekday."
      Throws:
      IllegalArgumentException - If minimum is greater than maximum.
    • assertDifferent

      public static void assertDifferent(long some, long other)
      Asserts that an integer value is different from some other integer value. The test failure explanation will include the number that was supposed to be different if the assertion fails.
      Parameters:
      some - The integer the other integer should not be. For example, 5777096943112551843.
      other - The other integer. For example, −6892550187484447930.
    • assertDifferent

      public static void assertDifferent(long some, long other, String msg)
      Asserts that an integer value is different from some other integer value.
      Parameters:
      some - The integer the other integer should not be. For example, −1674271114479202609.
      other - The other integer. For example, −3348542228958405218.
      msg - A message for the test failure explanation. If the assertion fails, the explanation will include the number that was expected to be different.
    • assertDifferent

      public static void assertDifferent(double some, double other)
      Asserts that a floating point value is different from some floating point value by more than DEFAULT_TEST_DELTA. The actual and expected differences will be included in the test explanation failure if the test fails because of the assertion.
      Parameters:
      some - A floating point value. For example, 3.141592653589793.
      other - A floating point value said to be different from some by more than the default variance. For example, 3.142857142857143.
    • assertDifferent

      public static void assertDifferent(double some, double other, double delta)
      Asserts that a floating point value is different from some floating point value by more than a specified variance. The actual and expected differences will be included in the test explanation failure if the test fails because of the assertion.
      Parameters:
      some - A floating point value. For example, 3.141592653589793.
      other - A floating point value said to be different from some by more than a specified variance. For example, 3.142857142857143.
      delta - The maximum allowable variance. For example, 0.00125. Should almost never be a subnormal value (remember that 0.0 is subnormal). We make no promises whatsoever regarding the accuracy of assertions involving subnormal values.
    • assertDifferent

      public static void assertDifferent(double some, double other, String msg)
      Asserts that a floating point value is different from some floating point value by more than DEFAULT_TEST_DELTA. The actual and expected differences will be included in the test explanation failure if the test fails because of the assertion.
      Parameters:
      some - A floating point value. For example, 3.141592653589793.
      other - A floating point value said to be different from some by more than the default variance. For example, 3.142857142857143.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertDifferent

      public static void assertDifferent(double some, double other, double delta, String msg)
      Asserts that a floating point value is different from some floating point value by more than a specified variance. The actual and expected differences will be included in the test explanation failure if the test fails because of the assertion.
      Parameters:
      some - A floating point value. For example, 3.141592653589793.
      other - A floating point value said to be different from some by more than a specified variance. For example, 3.142857142857143.
      delta - The maximum allowable variance. For example, 0.00125. Should almost never be a subnormal value (remember that 0.0 is subnormal). We make no promises whatsoever regarding the accuracy of assertions involving subnormal values.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertDifferent

      public static void assertDifferent(Object some, Object other)
      Asserts that two objects are different. Difference is determined by equals() returning false. The test failure explanation will include the object's toString() if the assertion fails.
      Parameters:
      some - An object to test for difference to another object. For example, a LocalDate object for today's date. It is this parameter's equals() function that will be called, but we reserve the right to change this in a later version.
      other - An object to assert is not the same as some. Preferably of the same runtime type as some. For example, a LocalDate object for tomorrow's date.
      Throws:
      NullPointerException - If either some or other is null.
    • assertDifferent

      public static void assertDifferent(Object some, Object other, String msg)
      Asserts that two objects are different. Difference is determined by equals() returning false.
      Parameters:
      some - An object to test for difference to another object. For example, a LocalDate object for today's date. It is this parameter's equals() function that will be called, but we reserve the right to change this in a later version.
      other - An object to assert is not the same as some. Preferably of the same runtime type as some. For example, a LocalDate object for tomorrow's date.
      msg - A message to include in the test failure explanation if the assertion fails.
      Throws:
      NullPointerException - If either some or other is null.
    • assertDifferent

      public static void assertDifferent(int[] some, int[] other)
      Asserts that two arrays of integers are different, in at least one of the elements if not in length. If the assertion fails, the test failure explanation will quote both arrays.
      Parameters:
      some - One of the arrays to assert is different from the other. For example, {1, 0, −1, −1, −2}.
      other - An array to assert is different from some array. For For example, {1, 0, −1, 0, −1}.
    • assertDifferent

      public static void assertDifferent(int[] some, int[] other, String msg)
      Asserts that two arrays of integers are different, in at least one of the elements if not in length.
      Parameters:
      some - One of the arrays to assert is different from the other. For example, {1, 0, −1, −1, −2}.
      other - An array to assert is different from some array. For example, {1, 0, −1, 0, −1}.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertDifferent

      public static void assertDifferent(double[] some, double[] other)
      Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than DEFAULT_TEST_DELTA. If the two arrays are the same length, the elements will be compared one by one starting with the element at index 0, and continuing until either finding an element that differs by more than DEFAULT_TEST_DELTA variance or reaching the end of the arrays. If no significant differences are found, the assertion will fail and the test failure explanation will quote both arrays.
      Parameters:
      some - An array to assert is different from the other. For example, {−0.5, 2.718281828459045, 3.141592653589793, 10.0}.
      other - The other array. For example, {−0.5, 2.718281828459045, 3.142857142857143, 10.0}.
      Throws:
      NullPointerException - If either array is null.
    • assertDifferent

      public static void assertDifferent(double[] some, double[] other, double delta)
      Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than a specified variance. If the two arrays are the same length, the elements will be compared one by one starting with the element at index 0, and continuing until either finding an element that differs by more than the specified variance or reaching the end of the arrays. If no significant differences are found, the assertion will fail and the test failure explanation will quote both arrays.
      Parameters:
      some - An array to assert is different from the other. For example, {−0.5, 2.718281828459045, 3.141592653589793, 10.0}.
      other - The other array. For example, {−0.5, 2.718281828459045, 3.142857142857143, 10.0}.
      delta - The maximum by which two numbers can differ and still be considered equal. Preferably a positive normalized number. For example, 0.001. The third element of the example some and other arrays differ by 0.0012644892673496777, so in this example the two arrays are considered different by more than the variance.
      Throws:
      NullPointerException - If either array is null.
    • assertDifferent

      public static void assertDifferent(double[] some, double[] other, String msg)
      Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than DEFAULT_TEST_DELTA. If the two arrays are the same length, the elements will be compared one by one starting with the element at index 0, and continuing until either finding an element that differs by more than DEFAULT_TEST_DELTA variance or reaching the end of the arrays. If no significant differences are found, the assertion will fail and the test failure explanation will quote both arrays.
      Parameters:
      some - An array to assert is different from the other. For example, {−0.5, 2.718281828459045, 3.141592653589793, 10.0}.
      other - The other array. For example, {−0.5, 2.718281828459045, 3.142857142857143, 10.0}.
      msg - A message to include in the test failure explanation if the assertion fails.
      Throws:
      NullPointerException - If either array is null.
    • assertDifferent

      public static void assertDifferent(double[] some, double[] other, double delta, String msg)
      Asserts that two arrays of 64-bit floating point numbers differ either in length or are the same length but at least one element differs by more than a specified variance. If the two arrays are the same length, the elements will be compared one by one starting with the element at index 0, and continuing until either finding an element that differs by more than the specified variance or reaching the end of the arrays. If no significant differences are found, the assertion will fail and the test failure explanation will quote both arrays.
      Parameters:
      some - An array to assert is different from the other. For example, {−0.5, 2.718281828459045, 3.141592653589793, 10.0}.
      other - The other array. For example, {−0.5, 2.718281828459045, 3.142857142857143, 10.0}.
      delta - The maximum by which two numbers can differ and still be considered equal. Preferably a positive normalized number. For example, 0.001. The third element of the example some and other arrays differ by 0.0012644892673496777, so in this example the two arrays are considered different by more than the variance.
      msg - A message to include in the test failure explanation if the assertion fails.
      Throws:
      NullPointerException - If either array is null.
    • assertDifferent

      public static <E> void assertDifferent(E[] some, E[] other)
      Asserts that two arrays of objects are different in some way, such as that they contain different elements, contain the same elements in a different order, or differ in length. The arrays may differ in that they have different memory addresses, but that does not matter for this assertion.
      Type Parameters:
      E - The type of the two arrays. For example, Pattern. Remember that this is only checked at compile time.
      Parameters:
      some - An array. For example, an array with a regular expression for e-mail addresses, a regular expression for Roman numerals, a regular expression for floating point numbers, and a null.
      other - An array said to be different from some. For example, an array with a regular expression for Roman numerals, a regular expression for e-mail addresses, a regular expression for Social Security numbers, and a null.
      Throws:
      NullPointerException - If some or other is null, but not if either array contains nulls.
    • assertDifferent

      public static <E> void assertDifferent(E[] some, E[] other, String msg)
      Asserts that two arrays of objects are different in some way, such as that they contain different elements, contain the same elements in a different order, or differ in length. The arrays may differ in that they have different memory addresses, but that does not matter for this assertion.
      Type Parameters:
      E - The type of the two arrays. For example, Pattern. Remember that this is only checked at compile time.
      Parameters:
      some - An array. For example, an array with a regular expression for e-mail addresses, a regular expression for Roman numerals, a regular expression for floating point numbers, and a null.
      other - An array said to be different from some. For example, an array with a regular expression for Roman numerals, a regular expression for e-mail addresses, a regular expression for Social Security numbers, and a null.
      msg - A message to include in the test failure explanation if the assertion fails.
      Throws:
      NullPointerException - If some or other is null, but not if either array contains nulls.
    • assertContains

      public static <E> void assertContains(E expected, E[] actual)
      Asserts the array contains the specified element. The test failure explanation will include the expected element and the elements contained in the array if the test fails because of the assertion.
      Type Parameters:
      E - The type of elements in the array. For example, DayOfWeek.
      Parameters:
      expected - The element expected to be in the array of type E. For example, Wednesday.
      actual - The array of type E. For example, the days Monday, Tuesday, Wednesday, Thursday and Friday.
      Throws:
      NullPointerException - If expected is null and actual is not an empty array.
    • assertContains

      public static <E> void assertContains(E expected, E[] actual, String msg)
      Asserts that an array contains a specified element. The test failure explanation will include the expected element and the elements contained in the array if the test fails because of the assertion, along with a customized message.
      Type Parameters:
      E - The type of elements in the array. For example, DayOfWeek.
      Parameters:
      expected - The element expected to be in the array of type E. For example, Wednesday.
      actual - The array of type E. For example, the days Monday, Tuesday, Wednesday, Thursday and Friday.
      msg - A message to append to the test failure explanation if the test fails because of the assertion.
      Throws:
      NullPointerException - If expected is null and actual is not an empty array.
    • assertContains

      public static <E> void assertContains(E expected, List<E> actual)
      Asserts that a list contains a specified element. The test failure explanation will include the expected element and the elements contained in the list if the test fails because of the assertion.
      Type Parameters:
      E - The type of elements in the list. For example, DayOfWeek.
      Parameters:
      expected - The element expected to be in the list of type E. For example, Wednesday.
      actual - The list of type E. For example, the days Monday, Tuesday, Wednesday, Thursday and Friday.
      Throws:
      NullPointerException - If expected is null, regardless of whether or not actual is an empty list. Depending on user feedback, this behavior might be changed so that a null expected does not cause this exception.
    • assertContains

      public static <E> void assertContains(E expected, List<E> actual, String msg)
      Asserts that a list contains a specified element. The test failure explanation will include the expected element and the elements contained in the list if the test fails because of the assertion, along with a customized message.
      Type Parameters:
      E - The type of elements in the list. For example, DayOfWeek.
      Parameters:
      expected - The element expected to be in the list of type E. For example, Wednesday.
      actual - The list of type E. For example, the days Monday, Tuesday, Wednesday, Thursday and Friday.
      msg - A message to append to the test failure explanation if the test fails because of the assertion.
      Throws:
      NullPointerException - If expected is null, regardless of whether or not actual is an empty list. Depending on user feedback, this behavior might be changed so that a null expected does not cause this exception.
    • assertContains

      public static <E> void assertContains(E expected, Set<E> actual)
      Asserts that a set contains a specified element. The test failure explanation will include the expected element and the elements contained in the set if the test fails because of the assertion.
      Type Parameters:
      E - The type of elements in the set. For example, Month.
      Parameters:
      expected - The element expected to be in the set of type E. For example, November.
      actual - The set of type E. For example, the months February, April, June, September and November.
      Throws:
      NullPointerException - If expected is null, regardless of whether or not actual is an empty set. Depending on user feedback, this behavior might be changed so that a null expected does not cause this exception.
    • assertContains

      public static <E> void assertContains(E expected, Set<E> actual, String msg)
      Asserts that a set contains a specified element. The test failure explanation will include the expected element and the elements contained in the set if the test fails because of the assertion, along with a customized message.
      Type Parameters:
      E - The type of elements in the set. For example, Month.
      Parameters:
      expected - The element expected to be in the set of type E. For example, November.
      actual - The set of type E. For example, the months January, March, May, July, August, October and December.
      msg - A message to append to the test failure explanation if the test fails because of the assertion.
      Throws:
      NullPointerException - If expected is null, regardless of whether or not actual is an empty set. Depending on user feedback, this behavior might be changed so that a null expected does not cause this exception.
    • assertContainsSame

      public static <E> void assertContainsSame(E[] expected, E[] actual)
      Asserts that two arrays contain the same elements, though not necessarily in the same order or the same quantities. One array may have fewer elements than the other, but the assertion won't fail as long as every element that appears in one array appears at least once in the other array.
      Type Parameters:
      E - The type of the elements in the two arrays. Remember that this is not checked at runtime. For example, java.time.Month.
      Parameters:
      expected - The array with the elements the other array is supposed to contain. For example, MARCH, APRIL, MAY and JUNE.
      actual - The array to check against expected. For example, APRIL, APRIL, JUNE, MARCH, MAY and MAY.
    • assertContainsSame

      public static <E> void assertContainsSame(E[] expected, E[] actual, String msg)
      Asserts that two arrays contain the same elements, though not necessarily in the same order or the same quantities. One array may have fewer elements than the other, but the assertion won't fail as long as every element that appears in one array appears at least once in the other array.
      Type Parameters:
      E - The type of the elements in the two arrays. Remember that this is not checked at runtime. For example, java.time.Month.
      Parameters:
      expected - The array with the elements the other array is supposed to contain. For example, MARCH, APRIL, MAY and JUNE.
      actual - The array to check against expected. For example, APRIL, APRIL, JUNE, MARCH, MAY and MAY.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertContainsSame

      public static <E> void assertContainsSame(List<E> expected, List<E> actual)
      Asserts that two lists contain the same elements, though not necessarily in the same order or the same quantities. The two lists may be different implementations of java.util.List. One list may have fewer elements than the other, but the assertion won't fail as long as every element that appears in one list appears at least once in the other list.
      Type Parameters:
      E - The type of the elements in the two lists. Remember that this is not checked at runtime. For example, java.time.Month.
      Parameters:
      expected - The list with the elements the other list is supposed to contain. For example, MARCH, APRIL, MAY and JUNE.
      actual - The list to check against expected. For example, APRIL, APRIL, JUNE, MARCH, MAY and MAY.
    • assertContainsSame

      public static <E> void assertContainsSame(List<E> expected, List<E> actual, String msg)
      Asserts that two lists contain the same elements, though not necessarily in the same order or the same quantities. The two lists may be different implementations of java.util.List. One list may have fewer elements than the other, but the assertion won't fail as long as every element that appears in one list appears at least once in the other list.
      Type Parameters:
      E - The type of the elements in the two lists. Remember that this is not checked at runtime. For example, java.time.Month.
      Parameters:
      expected - The list with the elements the other list is supposed to contain. For example, MARCH, APRIL, MAY and JUNE.
      actual - The list to check against expected. For example, APRIL, APRIL, JUNE, MARCH, MAY and MAY.
      msg - A message to include in the test failure explanation if the assertion fails.
    • assertContainsSame

      public static <E> void assertContainsSame(Set<E> expected, Set<E> actual)
      Asserts that two sets contain the same elements. The motivation for this assertion was the concern that two instances of different implementations of java.util.Set containing the same elements might cause a test calling assertEquals(Object, Object) to fail. For example, a test builds the expected set using Set.of(), then the actual set is initialized as an empty HashSet and the elements are added with repeated calls to the function under test. From my limited experimentation with HashSet, TreeSet and Set.of(), this concern might be unwarranted. Even so, at least for the time being, I recommend using this assertion instead of assertEquals() to assert that two sets contain the same elements without regard for runtime class.
      Type Parameters:
      E - The type of the elements that the sets contain. Remember that this is not checked at runtime. For example, LocalDate.
      Parameters:
      expected - The set with the expected elements. For example, July 1, 2024; July 2, 2024 and July July 3, 2024.
      actual - The set with the actual elements. For example, July 3, 2024; July 1, 2024 and July 2, 2024.
    • assertContainsSame

      public static <E> void assertContainsSame(Set<E> expected, Set<E> actual, String msg)
      Asserts that two sets contain the same elements. The motivation for this assertion was the concern that two instances of different implementations of java.util.Set containing the same elements might cause a test calling assertEquals(Object, Object, String) to fail. For example, a test builds the expected set using Set.of(), then the actual set is initialized as an empty HashSet and the elements are added with repeated calls to the function under test. From my limited experimentation with HashSet, TreeSet and Set.of(), this concern might be unwarranted. Even so, at least for the time being, I recommend using this assertion instead of assertEquals() to assert that two sets contain the same elements without regard for runtime class.
      Type Parameters:
      E - The type of the elements that the sets contain. Remember that this is not checked at runtime. For example, LocalDate.
      Parameters:
      expected - The set with the expected elements. For example, July 1, 2024; July 2, 2024 and July July 3, 2024.
      actual - The set with the actual elements. For example, July 3, 2024; July 1, 2024 and July 2, 2024.
      msg - A message to include in the test failure explanation if the assertion fails. For example, "Set of dates should include today and next two days."
    • assertContainsSameOrder

      public static <E> void assertContainsSameOrder(List<E> expected, List<E> actual)
      Asserts two lists contain the same elements in the same order. As long as the two lists have the same elements in the same order, even if the two lists are different implementations of java.util.List, the assertion will not fail. Both lists will be quoted in the test failure explanation if the test fails on account of order. To assert that two lists contain the same elements without regard for order, use assertContainsSame(List, List).
      Type Parameters:
      E - The type of the elements in the two lists. For example, LocalDate. Remember that this is not checked at runtime.
      Parameters:
      expected - A list with the expected order. For example, an ArrayList consisting of the dates March 31, 2024; April 4, 2021; April 9, 2023; April 17, 2022; April 20, 2025.
      actual - A list that is asserted to be in the same order as expected. For example, a LinkedList consisting of the dates April 4, 2021; April 17, 2022; April 9, 2023; March 31, 2024; April 20, 2025.
      Throws:
      NullPointerException - If expected and actual are of the same size but expected contains any nulls. And obviously also if either expected or actual is null.
    • assertContainsSameOrder

      public static <E> void assertContainsSameOrder(List<E> expected, List<E> actual, String msg)
      Asserts two lists contain the same elements in the same order. As long as the two lists have the same elements in the same order, even if the two lists are different implementations of java.util.List, the assertion will not fail. Both lists will be quoted in the test failure explanation if the test fails on account of order. To assert that two lists contain the same elements without regard for order, use assertContainsSame(List, List, String).
      Type Parameters:
      E - The type of the elements in the two lists. For example, LocalDate. Remember that this is not checked at runtime.
      Parameters:
      expected - A list with the expected order. For example, an ArrayList consisting of the dates March 31, 2024; April 4, 2021; April 9, 2023; April 17, 2022; April 20, 2025.
      actual - A list that is asserted to be in the same order as expected. For example, a LinkedList consisting of the dates April 4, 2021; April 17, 2022; April 9, 2023; March 31, 2024; April 20, 2025.
      msg - A message to include the test failure explanation. For example, "Easters should be listed in order by month and day, then year."
      Throws:
      NullPointerException - If expected and actual are of the same size but expected contains any nulls. And obviously also if either expected or actual is null.
    • assertPrintOut

      public static String assertPrintOut(Predicate<String> predicate, Procedure lambda, String msg)
      Makes a Boolean assertion about what a lambda sends to System.out. The normal System.out is rerouted to an interceptor at the beginning of this procedure, then restored at the end, provided no unrecoverable errors occur, nor that System.exit() is invoked.
      Parameters:
      predicate - A predicate about what should be sent to System.out. For example, a valid e-mail address should be included.
      lambda - A procedure to run, preferably one that includes at least one of System.out.print() or System.out.println().
      msg - A message that will be the entirety of the test failure explanation. This parameter is required, this assertion provides no default message. For example, "Printout should include e-mail address."
      Returns:
      What was printed to System.out. Beware of unexpected line endings and other system-dependent characteristics.
    • fail

      public static void fail(String msg)
      Fails a test regardless of anything else. Hence it generally makes sense to use this in a branch of a flow control statement. However, if you need it in a Try block or a Catch block, consider instead using assertThrows(org.testframe.api.Procedure, java.lang.Class<E>) or assertDoesNotThrow(org.testframe.api.Procedure).
      Parameters:
      msg - The message for the test failure explanation. Nothing will be appended to this message.
    • assertThrows

      public static <E extends Exception> E assertThrows(Procedure lambda, Class<E> exceptionType)
      Asserts that a given lambda caused an exception of a particular type. If the test fails because no exception was thrown or an exception of the wrong type was thrown, a default message to that effect will be provided.
      Type Parameters:
      E - The type of exception that should be thrown. For example, ArithmeticException.
      Parameters:
      lambda - The anonymous procedure that should throw the exception of the specified type. For example, () -> { Fraction badResult = oneHalf.divides(zero); }. It would be very similar in Scala.
      exceptionType - A Class object for the expected exception type. For example, ArithmeticException.class. Note that in Scala this would be classOf[ArithmeticException].
      Returns:
      An exception of the specified type. However, this is not guaranteed if assertions are not enabled. Then again, this whole class is useless if assertions are not enabled.
      Throws:
      NullPointerException - If lambda, exceptionType or msg is null.
    • assertThrows

      public static <E extends Exception> E assertThrows(Procedure lambda, Class<E> exceptionType, String msg)
      Asserts that a given lambda caused an exception of a particular type.
      Type Parameters:
      E - The type of exception that should be thrown. For example, ArithmeticException.
      Parameters:
      lambda - The anonymous procedure that should throw the exception of the specified type. For example, () -> { Fraction badResult = oneHalf.divides(zero); }. It would be very similar in Scala.
      exceptionType - A Class object for the expected exception type. For example, ArithmeticException.class. Note that in Scala this would be classOf[ArithmeticException].
      msg - A message for the test failure explanation. For example, "Division by zero should have caused an exception." If the assertion fails, either because an exception of the wrong type was thrown or because no exception was thrown, that information will be appended to the test failure explanation.
      Returns:
      An exception of the specified type. However, this is not guaranteed if assertions are not enabled. Then again, this whole class is useless if assertions are not enabled.
      Throws:
      NullPointerException - If lambda, exceptionType or msg is null.
    • assertDoesNotThrow

      public static void assertDoesNotThrow(Procedure lambda)
      Asserts that a given lambda does not throw exceptions of any type. A test failure explanation will be provided if any exception arises.
      Parameters:
      lambda - The anonymous procedure that should not throw any exceptions. For example, () -> { arrayBackedList.expandCapacity; }.
      Throws:
      NullPointerException - If lambda or msg is null.
    • assertDoesNotThrow

      public static void assertDoesNotThrow(Procedure lambda, String msg)
      Asserts that a given lambda does not throw exceptions of any type.
      Parameters:
      lambda - The anonymous procedure that should not throw any exceptions. For example, () -> { arrayBackedList.expandCapacity; }.
      msg - A message for the test failure explanation. For example, "Expanding list capacity should not cause any exceptions." If an exception does occur, that will be appended to the test failure explanation. For example, "No exceptions should have occurred but ArrayIndexOutOfBoundsException did."
      Throws:
      NullPointerException - If lambda or msg is null.
    • assertTimeout

      public static void assertTimeout(Procedure lambda, Duration allottedTime, String msg)
      Asserts that a lambda completes in a certain amount of time. A new thread is started to run the lambda on.
      Parameters:
      lambda - The anonymous procedure that should run in a certain amount of time. For example, a lambda that adds up the values of all of a customer's pending transactions to calculate the net change on the account if all those transactions go through.
      allottedTime - How much time to allow the procedure to run in. For example, 5 seconds. Should generally be much less than a minute. We make no guarantees as to how precisely the time will be measured. Allow a grace period of as much as a full second.
      msg - A message to include in the test failure explanation if the assertion fails after running out of time. For example, "All of the customer's pending transactions should've been added up in less than 5 seconds."
      Throws:
      ArithmeticException - If allottedTime in milliseconds is greater than Long.MAX_VALUE.