Class Assertions


  • @API(status=STABLE,
         since="5.0")
    public class Assertions
    extends Object
    Assertions is a collection of utility methods that support asserting conditions in tests.

    Additional Kotlin assertions can be found as top-level functions in the org.junit.jupiter.api package.

    Unless otherwise noted, a failed assertion will throw an AssertionFailedError or a subclass thereof.

    Although it is technically possible to extend this class, extension is strongly discouraged. The JUnit Team highly recommends that the methods defined in this class be used via static imports.

    Since:
    5.0
    See Also:
    AssertionFailedError, Assumptions
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Assertions()
      Protected constructor allowing subclassing but not direct instantiation.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertAll​(String heading, Collection<Executable> executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertAll​(String heading, Stream<Executable> executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertAll​(String heading, Executable... executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertAll​(Collection<Executable> executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertAll​(Stream<Executable> executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertAll​(Executable... executables)
      Asserts that all supplied executables do not throw exceptions.
      static void assertArrayEquals​(boolean[] expected, boolean[] actual)
      Asserts that expected and actual boolean arrays are equal.
      static void assertArrayEquals​(boolean[] expected, boolean[] actual, String message)
      Asserts that expected and actual boolean arrays are equal.
      static void assertArrayEquals​(boolean[] expected, boolean[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual boolean arrays are equal.
      static void assertArrayEquals​(byte[] expected, byte[] actual)
      Asserts that expected and actual byte arrays are equal.
      static void assertArrayEquals​(byte[] expected, byte[] actual, String message)
      Asserts that expected and actual byte arrays are equal.
      static void assertArrayEquals​(byte[] expected, byte[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual byte arrays are equal.
      static void assertArrayEquals​(char[] expected, char[] actual)
      Asserts that expected and actual char arrays are equal.
      static void assertArrayEquals​(char[] expected, char[] actual, String message)
      Asserts that expected and actual char arrays are equal.
      static void assertArrayEquals​(char[] expected, char[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual char arrays are equal.
      static void assertArrayEquals​(double[] expected, double[] actual)
      Asserts that expected and actual double arrays are equal.
      static void assertArrayEquals​(double[] expected, double[] actual, double delta)
      Asserts that expected and actual double arrays are equal within the given delta.
      static void assertArrayEquals​(double[] expected, double[] actual, double delta, String message)
      Asserts that expected and actual double arrays are equal within the given delta.
      static void assertArrayEquals​(double[] expected, double[] actual, double delta, Supplier<String> messageSupplier)
      Asserts that expected and actual double arrays are equal within the given delta.
      static void assertArrayEquals​(double[] expected, double[] actual, String message)
      Asserts that expected and actual double arrays are equal.
      static void assertArrayEquals​(double[] expected, double[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual double arrays are equal.
      static void assertArrayEquals​(float[] expected, float[] actual)
      Asserts that expected and actual float arrays are equal.
      static void assertArrayEquals​(float[] expected, float[] actual, float delta)
      Asserts that expected and actual float arrays are equal within the given delta.
      static void assertArrayEquals​(float[] expected, float[] actual, float delta, String message)
      Asserts that expected and actual float arrays are equal within the given delta.
      static void assertArrayEquals​(float[] expected, float[] actual, float delta, Supplier<String> messageSupplier)
      Asserts that expected and actual float arrays are equal within the given delta.
      static void assertArrayEquals​(float[] expected, float[] actual, String message)
      Asserts that expected and actual float arrays are equal.
      static void assertArrayEquals​(float[] expected, float[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual float arrays are equal.
      static void assertArrayEquals​(int[] expected, int[] actual)
      Asserts that expected and actual int arrays are equal.
      static void assertArrayEquals​(int[] expected, int[] actual, String message)
      Asserts that expected and actual int arrays are equal.
      static void assertArrayEquals​(int[] expected, int[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual int arrays are equal.
      static void assertArrayEquals​(long[] expected, long[] actual)
      Asserts that expected and actual long arrays are equal.
      static void assertArrayEquals​(long[] expected, long[] actual, String message)
      Asserts that expected and actual long arrays are equal.
      static void assertArrayEquals​(long[] expected, long[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual long arrays are equal.
      static void assertArrayEquals​(short[] expected, short[] actual)
      Asserts that expected and actual short arrays are equal.
      static void assertArrayEquals​(short[] expected, short[] actual, String message)
      Asserts that expected and actual short arrays are equal.
      static void assertArrayEquals​(short[] expected, short[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual short arrays are equal.
      static void assertArrayEquals​(Object[] expected, Object[] actual)
      Asserts that expected and actual object arrays are deeply equal.
      static void assertArrayEquals​(Object[] expected, Object[] actual, String message)
      Asserts that expected and actual object arrays are deeply equal.
      static void assertArrayEquals​(Object[] expected, Object[] actual, Supplier<String> messageSupplier)
      Asserts that expected and actual object arrays are deeply equal.
      static void assertDoesNotThrow​(Executable executable)
      Asserts that execution of the supplied executable does not throw any kind of exception.
      static void assertDoesNotThrow​(Executable executable, String message)
      Asserts that execution of the supplied executable does not throw any kind of exception.
      static void assertDoesNotThrow​(Executable executable, Supplier<String> messageSupplier)
      Asserts that execution of the supplied executable does not throw any kind of exception.
      static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier)
      Asserts that execution of the supplied supplier does not throw any kind of exception.
      static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier, String message)
      Asserts that execution of the supplied supplier does not throw any kind of exception.
      static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier, Supplier<String> messageSupplier)
      Asserts that execution of the supplied supplier does not throw any kind of exception.
      static void assertEquals​(byte expected, byte actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(byte expected, byte actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(byte expected, byte actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(char expected, char actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(char expected, char actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(char expected, char actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(double expected, double actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(double expected, double actual, double delta)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(double expected, double actual, double delta, String message)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(double expected, double actual, double delta, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(double expected, double actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(double expected, double actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(float expected, float actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(float expected, float actual, float delta)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(float expected, float actual, float delta, String message)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(float expected, float actual, float delta, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal within the given delta.
      static void assertEquals​(float expected, float actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(float expected, float actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(int expected, int actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(int expected, int actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(int expected, int actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(long expected, long actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(long expected, long actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(long expected, long actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(short expected, short actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(short expected, short actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(short expected, short actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertEquals​(Object expected, Object actual)
      Asserts that expected and actual are equal.
      static void assertEquals​(Object expected, Object actual, String message)
      Asserts that expected and actual are equal.
      static void assertEquals​(Object expected, Object actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are equal.
      static void assertFalse​(boolean condition)
      Asserts that the supplied condition is not true.
      static void assertFalse​(boolean condition, String message)
      Asserts that the supplied condition is not true.
      static void assertFalse​(boolean condition, Supplier<String> messageSupplier)
      Asserts that the supplied condition is not true.
      static void assertFalse​(BooleanSupplier booleanSupplier)
      Asserts that the boolean condition supplied by booleanSupplier is not true.
      static void assertFalse​(BooleanSupplier booleanSupplier, String message)
      Asserts that the boolean condition supplied by booleanSupplier is not true.
      static void assertFalse​(BooleanSupplier booleanSupplier, Supplier<String> messageSupplier)
      Asserts that the boolean condition supplied by booleanSupplier is not true.
      static void assertIterableEquals​(Iterable<?> expected, Iterable<?> actual)
      Asserts that expected and actual iterables are deeply equal.
      static void assertIterableEquals​(Iterable<?> expected, Iterable<?> actual, String message)
      Asserts that expected and actual iterables are deeply equal.
      static void assertIterableEquals​(Iterable<?> expected, Iterable<?> actual, Supplier<String> messageSupplier)
      Asserts that expected and actual iterables are deeply equal.
      static void assertLinesMatch​(List<String> expectedLines, List<String> actualLines)
      Asserts that expected list of Strings matches actual list.
      static void assertNotEquals​(Object unexpected, Object actual)
      Asserts that expected and actual are not equal.
      static void assertNotEquals​(Object unexpected, Object actual, String message)
      Asserts that expected and actual are not equal.
      static void assertNotEquals​(Object unexpected, Object actual, Supplier<String> messageSupplier)
      Asserts that expected and actual are not equal.
      static void assertNotNull​(Object actual)
      Asserts that actual is not null.
      static void assertNotNull​(Object actual, String message)
      Asserts that actual is not null.
      static void assertNotNull​(Object actual, Supplier<String> messageSupplier)
      Asserts that actual is not null.
      static void assertNotSame​(Object unexpected, Object actual)
      Asserts that expected and actual do not refer to the same object.
      static void assertNotSame​(Object unexpected, Object actual, String message)
      Asserts that expected and actual do not refer to the same object.
      static void assertNotSame​(Object unexpected, Object actual, Supplier<String> messageSupplier)
      Asserts that expected and actual do not refer to the same object.
      static void assertNull​(Object actual)
      Asserts that actual is null.
      static void assertNull​(Object actual, String message)
      Asserts that actual is null.
      static void assertNull​(Object actual, Supplier<String> messageSupplier)
      Asserts that actual is null.
      static void assertSame​(Object expected, Object actual)
      Asserts that expected and actual refer to the same object.
      static void assertSame​(Object expected, Object actual, String message)
      Asserts that expected and actual refer to the same object.
      static void assertSame​(Object expected, Object actual, Supplier<String> messageSupplier)
      Asserts that expected and actual refer to the same object.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, Executable executable)
      Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, Executable executable, String message)
      Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, Executable executable, Supplier<String> messageSupplier)
      Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, ThrowingSupplier<?> supplier)
      Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, ThrowingSupplier<?> supplier, String message)
      Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.
      static <T extends Throwable>
      T
      assertThrows​(Class<T> expectedType, ThrowingSupplier<?> supplier, Supplier<String> messageSupplier)
      Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.
      static void assertTimeout​(Duration timeout, Executable executable)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static void assertTimeout​(Duration timeout, Executable executable, String message)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static void assertTimeout​(Duration timeout, Executable executable, Supplier<String> messageSupplier)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static <T> T assertTimeout​(Duration timeout, ThrowingSupplier<T> supplier)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static <T> T assertTimeout​(Duration timeout, ThrowingSupplier<T> supplier, String message)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static <T> T assertTimeout​(Duration timeout, ThrowingSupplier<T> supplier, Supplier<String> messageSupplier)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static void assertTimeoutPreemptively​(Duration timeout, Executable executable)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static void assertTimeoutPreemptively​(Duration timeout, Executable executable, String message)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static void assertTimeoutPreemptively​(Duration timeout, Executable executable, Supplier<String> messageSupplier)
      Asserts that execution of the supplied executable completes before the given timeout is exceeded.
      static <T> T assertTimeoutPreemptively​(Duration timeout, ThrowingSupplier<T> supplier)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static <T> T assertTimeoutPreemptively​(Duration timeout, ThrowingSupplier<T> supplier, String message)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static <T> T assertTimeoutPreemptively​(Duration timeout, ThrowingSupplier<T> supplier, Supplier<String> messageSupplier)
      Asserts that execution of the supplied supplier completes before the given timeout is exceeded.
      static void assertTrue​(boolean condition)
      Asserts that the supplied condition is true.
      static void assertTrue​(boolean condition, String message)
      Asserts that the supplied condition is true.
      static void assertTrue​(boolean condition, Supplier<String> messageSupplier)
      Asserts that the supplied condition is true.
      static void assertTrue​(BooleanSupplier booleanSupplier)
      Asserts that the boolean condition supplied by booleanSupplier is true.
      static void assertTrue​(BooleanSupplier booleanSupplier, String message)
      Asserts that the boolean condition supplied by booleanSupplier is true.
      static void assertTrue​(BooleanSupplier booleanSupplier, Supplier<String> messageSupplier)
      Asserts that the boolean condition supplied by booleanSupplier is true.
      static <V> V fail()
      Fails a test without a failure message.
      static <V> V fail​(String message)
      Fails a test with the given failure message.
      static <V> V fail​(String message, Throwable cause)
      Fails a test with the given failure message as well as the underlying cause.
      static <V> V fail​(Throwable cause)
      Fails a test with the given underlying cause.
      static <V> V fail​(Supplier<String> messageSupplier)
      Fails a test with the failure message retrieved from the given messageSupplier.
    • Constructor Detail

      • Assertions

        protected Assertions()
        Protected constructor allowing subclassing but not direct instantiation.
        Since:
        5.3
    • Method Detail

      • fail

        public static <V> V fail()
        Fails a test without a failure message.

        Although failing with an explicit failure message is recommended, this method may be useful when maintaining legacy code.

        See Javadoc for fail(String, Throwable) for an explanation of this method's generic return type V.

      • fail

        public static <V> V fail​(String message)
        Fails a test with the given failure message.

        See Javadoc for fail(String, Throwable) for an explanation of this method's generic return type V.

      • fail

        public static <V> V fail​(String message,
                                 Throwable cause)
        Fails a test with the given failure message as well as the underlying cause.

        The generic return type V allows this method to be used directly as a single-statement lambda expression, thereby avoiding the need to implement a code block with an explicit return value. Since this method throws an AssertionFailedError before its return statement, this method never actually returns a value to its caller. The following example demonstrates how this may be used in practice.

        
         Stream.of().map(entry -> fail("should not be called"));
         
      • fail

        public static <V> V fail​(Throwable cause)
        Fails a test with the given underlying cause.

        See Javadoc for fail(String, Throwable) for an explanation of this method's generic return type V.

      • fail

        public static <V> V fail​(Supplier<String> messageSupplier)
        Fails a test with the failure message retrieved from the given messageSupplier.

        See Javadoc for fail(String, Throwable) for an explanation of this method's generic return type V.

      • assertTrue

        public static void assertTrue​(boolean condition)
        Asserts that the supplied condition is true.
      • assertTrue

        public static void assertTrue​(boolean condition,
                                      Supplier<String> messageSupplier)
        Asserts that the supplied condition is true.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertTrue

        public static void assertTrue​(BooleanSupplier booleanSupplier)
        Asserts that the boolean condition supplied by booleanSupplier is true.
      • assertTrue

        public static void assertTrue​(BooleanSupplier booleanSupplier,
                                      String message)
        Asserts that the boolean condition supplied by booleanSupplier is true.

        Fails with the supplied failure message.

      • assertTrue

        public static void assertTrue​(boolean condition,
                                      String message)
        Asserts that the supplied condition is true.

        Fails with the supplied failure message.

      • assertTrue

        public static void assertTrue​(BooleanSupplier booleanSupplier,
                                      Supplier<String> messageSupplier)
        Asserts that the boolean condition supplied by booleanSupplier is true.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertFalse

        public static void assertFalse​(boolean condition)
        Asserts that the supplied condition is not true.
      • assertFalse

        public static void assertFalse​(boolean condition,
                                       String message)
        Asserts that the supplied condition is not true.

        Fails with the supplied failure message.

      • assertFalse

        public static void assertFalse​(boolean condition,
                                       Supplier<String> messageSupplier)
        Asserts that the supplied condition is not true.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertFalse

        public static void assertFalse​(BooleanSupplier booleanSupplier)
        Asserts that the boolean condition supplied by booleanSupplier is not true.
      • assertFalse

        public static void assertFalse​(BooleanSupplier booleanSupplier,
                                       String message)
        Asserts that the boolean condition supplied by booleanSupplier is not true.

        Fails with the supplied failure message.

      • assertFalse

        public static void assertFalse​(BooleanSupplier booleanSupplier,
                                       Supplier<String> messageSupplier)
        Asserts that the boolean condition supplied by booleanSupplier is not true.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertNull

        public static void assertNull​(Object actual)
        Asserts that actual is null.
      • assertNull

        public static void assertNull​(Object actual,
                                      String message)
        Asserts that actual is null.

        Fails with the supplied failure message.

      • assertNull

        public static void assertNull​(Object actual,
                                      Supplier<String> messageSupplier)
        Asserts that actual is null.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertNotNull

        public static void assertNotNull​(Object actual)
        Asserts that actual is not null.
      • assertNotNull

        public static void assertNotNull​(Object actual,
                                         String message)
        Asserts that actual is not null.

        Fails with the supplied failure message.

      • assertNotNull

        public static void assertNotNull​(Object actual,
                                         Supplier<String> messageSupplier)
        Asserts that actual is not null.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(short expected,
                                        short actual)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(short expected,
                                        short actual,
                                        String message)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(short expected,
                                        short actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(byte expected,
                                        byte actual)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(byte expected,
                                        byte actual,
                                        String message)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(byte expected,
                                        byte actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(int expected,
                                        int actual)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(int expected,
                                        int actual,
                                        String message)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(int expected,
                                        int actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(long expected,
                                        long actual)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(long expected,
                                        long actual,
                                        String message)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(long expected,
                                        long actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(char expected,
                                        char actual)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(char expected,
                                        char actual,
                                        String message)
        Asserts that expected and actual are equal.
      • assertEquals

        public static void assertEquals​(char expected,
                                        char actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(float expected,
                                        float actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(float expected,
                                        float actual,
                                        float delta)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

      • assertEquals

        public static void assertEquals​(float expected,
                                        float actual,
                                        float delta,
                                        String message)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

      • assertEquals

        public static void assertEquals​(float expected,
                                        float actual,
                                        float delta,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(double expected,
                                        double actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(double expected,
                                        double actual,
                                        double delta)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

      • assertEquals

        public static void assertEquals​(double expected,
                                        double actual,
                                        double delta,
                                        String message)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

      • assertEquals

        public static void assertEquals​(double expected,
                                        double actual,
                                        double delta,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertEquals

        public static void assertEquals​(Object expected,
                                        Object actual)
        Asserts that expected and actual are equal.

        If both are null, they are considered equal.

        See Also:
        Object.equals(Object)
      • assertEquals

        public static void assertEquals​(Object expected,
                                        Object actual,
                                        String message)
        Asserts that expected and actual are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

        See Also:
        Object.equals(Object)
      • assertEquals

        public static void assertEquals​(Object expected,
                                        Object actual,
                                        Supplier<String> messageSupplier)
        Asserts that expected and actual are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        See Also:
        Object.equals(Object)
      • assertArrayEquals

        public static void assertArrayEquals​(boolean[] expected,
                                             boolean[] actual)
        Asserts that expected and actual boolean arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(boolean[] expected,
                                             boolean[] actual,
                                             String message)
        Asserts that expected and actual boolean arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(boolean[] expected,
                                             boolean[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual boolean arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(char[] expected,
                                             char[] actual)
        Asserts that expected and actual char arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(char[] expected,
                                             char[] actual,
                                             String message)
        Asserts that expected and actual char arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(char[] expected,
                                             char[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual char arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(byte[] expected,
                                             byte[] actual)
        Asserts that expected and actual byte arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(byte[] expected,
                                             byte[] actual,
                                             String message)
        Asserts that expected and actual byte arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(byte[] expected,
                                             byte[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual byte arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(short[] expected,
                                             short[] actual)
        Asserts that expected and actual short arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(short[] expected,
                                             short[] actual,
                                             String message)
        Asserts that expected and actual short arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(short[] expected,
                                             short[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual short arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(int[] expected,
                                             int[] actual)
        Asserts that expected and actual int arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(int[] expected,
                                             int[] actual,
                                             String message)
        Asserts that expected and actual int arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(int[] expected,
                                             int[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual int arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(long[] expected,
                                             long[] actual)
        Asserts that expected and actual long arrays are equal.

        If both are null, they are considered equal.

      • assertArrayEquals

        public static void assertArrayEquals​(long[] expected,
                                             long[] actual,
                                             String message)
        Asserts that expected and actual long arrays are equal.

        If both are null, they are considered equal.

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(long[] expected,
                                             long[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual long arrays are equal.

        If both are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual)
        Asserts that expected and actual float arrays are equal.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual,
                                             String message)
        Asserts that expected and actual float arrays are equal.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual float arrays are equal.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual,
                                             float delta)
        Asserts that expected and actual float arrays are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual,
                                             float delta,
                                             String message)
        Asserts that expected and actual float arrays are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(float[] expected,
                                             float[] actual,
                                             float delta,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual float arrays are equal within the given delta.

        Equality imposed by this method is consistent with Float.equals(Object) and Float.compare(float, float).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual)
        Asserts that expected and actual double arrays are equal.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual,
                                             String message)
        Asserts that expected and actual double arrays are equal.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual double arrays are equal.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual,
                                             double delta)
        Asserts that expected and actual double arrays are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual,
                                             double delta,
                                             String message)
        Asserts that expected and actual double arrays are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        Fails with the supplied failure message.

      • assertArrayEquals

        public static void assertArrayEquals​(double[] expected,
                                             double[] actual,
                                             double delta,
                                             Supplier<String> messageSupplier)
        Asserts that expected and actual double arrays are equal within the given delta.

        Equality imposed by this method is consistent with Double.equals(Object) and Double.compare(double, double).

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertIterableEquals

        public static void assertIterableEquals​(Iterable<?> expected,
                                                Iterable<?> actual)
        Asserts that expected and actual iterables are deeply equal.

        Similarly to the check for deep equality in assertArrayEquals(Object[], Object[]), if two iterables are encountered (including expected and actual) then their iterators must return equal elements in the same order as each other. Note: this means that the iterables do not need to be of the same type. Example:

        
         import static java.util.Arrays.asList;
          . . .
         Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
         Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
         assertIterableEquals(i0, i1); // Passes
         

        If both expected and actual are null, they are considered equal.

        See Also:
        Objects.equals(Object, Object), Arrays.deepEquals(Object[], Object[]), assertArrayEquals(Object[], Object[])
      • assertIterableEquals

        public static void assertIterableEquals​(Iterable<?> expected,
                                                Iterable<?> actual,
                                                String message)
        Asserts that expected and actual iterables are deeply equal.

        Similarly to the check for deep equality in assertArrayEquals(Object[], Object[], String), if two iterables are encountered (including expected and actual) then their iterators must return equal elements in the same order as each other. Note: this means that the iterables do not need to be of the same type. Example:

        
         import static java.util.Arrays.asList;
          . . .
         Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
         Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
         assertIterableEquals(i0, i1); // Passes
         

        If both expected and actual are null, they are considered equal.

        Fails with the supplied failure message.

        See Also:
        Objects.equals(Object, Object), Arrays.deepEquals(Object[], Object[]), assertArrayEquals(Object[], Object[], String)
      • assertIterableEquals

        public static void assertIterableEquals​(Iterable<?> expected,
                                                Iterable<?> actual,
                                                Supplier<String> messageSupplier)
        Asserts that expected and actual iterables are deeply equal.

        Similarly to the check for deep equality in assertArrayEquals(Object[], Object[], Supplier), if two iterables are encountered (including expected and actual) then their iterators must return equal elements in the same order as each other. Note: this means that the iterables do not need to be of the same type. Example:

        
         import static java.util.Arrays.asList;
          . . .
         Iterable<Integer> i0 = new ArrayList<>(asList(1, 2, 3));
         Iterable<Integer> i1 = new LinkedList<>(asList(1, 2, 3));
         assertIterableEquals(i0, i1); // Passes
         

        If both expected and actual are null, they are considered equal.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        See Also:
        Objects.equals(Object, Object), Arrays.deepEquals(Object[], Object[]), assertArrayEquals(Object[], Object[], Supplier)
      • assertLinesMatch

        public static void assertLinesMatch​(List<String> expectedLines,
                                            List<String> actualLines)
        Asserts that expected list of Strings matches actual list.

        This method differs from other assertions that effectively only check String.equals(Object), in that it uses the following staged matching algorithm:

        For each pair of expected and actual lines do

        1. check if expected.equals(actual) - if yes, continue with next pair
        2. otherwise treat expected as a regular expression and check via String.matches(String) - if yes, continue with next pair
        3. otherwise check if expected line is a fast-forward marker, if yes apply fast-forward actual lines accordingly (see below) and goto 1.

        A valid fast-forward marker is an expected line that starts and ends with the literal >> and contains at least 4 characters. Examples:

        • >>>>
          >> stacktrace >>
          >> single line, non Integer.parse()-able comment >>
          Skip arbitrary number of actual lines, until first matching subsequent expected line is found. Any character between the fast-forward literals are discarded.
        • ">> 21 >>"
          Skip strictly 21 lines. If they can't be skipped for any reason, an assertion error is raised.

        Here is an example showing all three kinds of expected line formats:

        
         ls -la /
         total [\d]+
         drwxr-xr-x  0 root root   512 Jan  1  1970 .
         drwxr-xr-x  0 root root   512 Jan  1  1970 ..
         drwxr-xr-x  0 root root   512 Apr  5 07:45 bin
         >> 4 >>
         -rwxr-xr-x  1 root root [\d]+ Jan  1  1970 init
         >> M A N Y  M O R E  E N T R I E S >>
         drwxr-xr-x  0 root root   512 Sep 22  2017 var
         
      • assertNotEquals

        public static void assertNotEquals​(Object unexpected,
                                           Object actual)
        Asserts that expected and actual are not equal.

        Fails if both are null.

        See Also:
        Object.equals(Object)
      • assertNotEquals

        public static void assertNotEquals​(Object unexpected,
                                           Object actual,
                                           String message)
        Asserts that expected and actual are not equal.

        Fails if both are null.

        Fails with the supplied failure message.

        See Also:
        Object.equals(Object)
      • assertNotEquals

        public static void assertNotEquals​(Object unexpected,
                                           Object actual,
                                           Supplier<String> messageSupplier)
        Asserts that expected and actual are not equal.

        Fails if both are null.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        See Also:
        Object.equals(Object)
      • assertSame

        public static void assertSame​(Object expected,
                                      Object actual)
        Asserts that expected and actual refer to the same object.
      • assertSame

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

        Fails with the supplied failure message.

      • assertSame

        public static void assertSame​(Object expected,
                                      Object actual,
                                      Supplier<String> messageSupplier)
        Asserts that expected and actual refer to the same object.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertNotSame

        public static void assertNotSame​(Object unexpected,
                                         Object actual)
        Asserts that expected and actual do not refer to the same object.
      • assertNotSame

        public static void assertNotSame​(Object unexpected,
                                         Object actual,
                                         String message)
        Asserts that expected and actual do not refer to the same object.

        Fails with the supplied failure message.

      • assertNotSame

        public static void assertNotSame​(Object unexpected,
                                         Object actual,
                                         Supplier<String> messageSupplier)
        Asserts that expected and actual do not refer to the same object.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           Executable executable)
        Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           Executable executable,
                                                           String message)
        Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           Executable executable,
                                                           Supplier<String> messageSupplier)
        Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           ThrowingSupplier<?> supplier)
        Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If the given ThrowingSupplier returns a result instead of throwing an exception, the result will be included in the failure message.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

        Since:
        5.3
      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           ThrowingSupplier<?> supplier,
                                                           String message)
        Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If the given ThrowingSupplier returns a result instead of throwing an exception, the result will be included in the failure message.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

        Since:
        5.3
      • assertThrows

        public static <T extends Throwable> T assertThrows​(Class<T> expectedType,
                                                           ThrowingSupplier<?> supplier,
                                                           Supplier<String> messageSupplier)
        Asserts that execution of the given supplier throws an exception of the expectedType and returns the exception.

        If no exception is thrown, or if an exception of a different type is thrown, this method will fail.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        If the given ThrowingSupplier returns a result instead of throwing an exception, the result will be included in the failure message.

        If you do not want to perform additional checks on the exception instance, simply ignore the return value.

        Since:
        5.3
      • assertDoesNotThrow

        public static void assertDoesNotThrow​(Executable executable)
        Asserts that execution of the supplied executable does not throw any kind of exception.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.

        Since:
        5.2
      • assertDoesNotThrow

        public static void assertDoesNotThrow​(Executable executable,
                                              String message)
        Asserts that execution of the supplied executable does not throw any kind of exception.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.

        Since:
        5.2
      • assertDoesNotThrow

        public static void assertDoesNotThrow​(Executable executable,
                                              Supplier<String> messageSupplier)
        Asserts that execution of the supplied executable does not throw any kind of exception.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        Since:
        5.2
      • assertDoesNotThrow

        public static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier)
        Asserts that execution of the supplied supplier does not throw any kind of exception.

        If the assertion passes, the supplier's result will be returned.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.

      • assertDoesNotThrow

        public static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier,
                                               String message)
        Asserts that execution of the supplied supplier does not throw any kind of exception.

        If the assertion passes, the supplier's result will be returned.

        Fails with the supplied failure message.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.

      • assertDoesNotThrow

        public static <T> T assertDoesNotThrow​(ThrowingSupplier<T> supplier,
                                               Supplier<String> messageSupplier)
        Asserts that execution of the supplied supplier does not throw any kind of exception.

        If the assertion passes, the supplier's result will be returned.

        If necessary, the failure message will be retrieved lazily from the supplied messageSupplier.

        Usage Note

        Although any exception thrown from a test method will cause the test to fail, there are certain use cases where it can be beneficial to explicitly assert that an exception is not thrown for a given code block within a test method.