Class ThrowableAssertions


  • public final class ThrowableAssertions
    extends Object
    A collection of utility methods that support asserting conditions in tests for throwables and code that should or should not throw any exceptions, in addition to what is already provided by Assertions.
    Author:
    Rob Spoor
    Since:
    2.0
    • Method Detail

      • assertHasDirectCause

        public static <T extends Throwable> T assertHasDirectCause​(Class<T> expectedType,
                                                                   Throwable throwable)
        Asserts that the supplied throwable has a direct cause of the given type, and returns this cause.

        If the throwable has no cause, or the direct cause has a different type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        Returns:
        The direct cause of the given exception, cast to the given type.
      • assertHasDirectCause

        public static <T extends Throwable> T assertHasDirectCause​(Class<T> expectedType,
                                                                   Throwable throwable,
                                                                   String message)
        Asserts that the supplied throwable has a cause, directly or indirectly, of the given type, and returns this cause.

        If the throwable has no cause, or the direct cause has a different type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        message - The failure message to fail with.
        Returns:
        The direct cause of the given exception, cast to the given type.
      • assertHasDirectCause

        public static <T extends Throwable> T assertHasDirectCause​(Class<T> expectedType,
                                                                   Throwable throwable,
                                                                   Supplier<String> messageSupplier)
        Asserts that the supplied throwable has a cause, directly or indirectly, of the given type, and returns this cause.

        If the throwable has no cause, or the direct cause has a different type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The direct cause of the given exception, cast to the given type.
      • assertHasCause

        public static <T extends Throwable> T assertHasCause​(Class<T> expectedType,
                                                             Throwable throwable)
        Asserts that the supplied throwable has a cause, directly or indirectly, of the given type, and returns this cause.

        If the throwable has no cause, or has no direct or indirect cause of the given type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        Returns:
        The nearest cause of the given exception with the given type.
      • assertHasCause

        public static <T extends Throwable> T assertHasCause​(Class<T> expectedType,
                                                             Throwable throwable,
                                                             String message)
        Asserts that the supplied throwable has a cause, directly or indirectly, of the given type, and returns this cause.

        If the throwable has no cause, or has no direct or indirect cause of the given type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        message - The failure message to fail with.
        Returns:
        The nearest cause of the given exception with the given type.
      • assertHasCause

        public static <T extends Throwable> T assertHasCause​(Class<T> expectedType,
                                                             Throwable throwable,
                                                             Supplier<String> messageSupplier)
        Asserts that the supplied throwable has a cause, directly or indirectly, of the given type, and returns this cause.

        If the throwable has no cause, or has no direct or indirect cause of the given type, this method will fail.

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

        Type Parameters:
        T - The expected cause type.
        Parameters:
        expectedType - The expected cause type.
        throwable - The throwable to check.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The nearest cause of the given exception with the given type.
      • assertOptionallyThrows

        public static <T extends ThrowableOptional<T> assertOptionallyThrows​(Class<T> expectedType,
                                                                               Executable executable)
        Asserts that execution of the supplied Executable throws an exception of the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable)
      • assertOptionallyThrows

        public static <T extends ThrowableOptional<T> assertOptionallyThrows​(Class<T> expectedType,
                                                                               Executable executable,
                                                                               String message)
        Asserts that execution of the supplied Executable throws an exception of the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, String)
      • assertOptionallyThrows

        public static <T extends ThrowableOptional<T> assertOptionallyThrows​(Class<T> expectedType,
                                                                               Executable executable,
                                                                               Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, Supplier)
      • assertOptionallyThrowsExactly

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactly​(Class<T> expectedType,
                                                                                      Executable executable)
        Asserts that execution of the supplied Executable throws an exception of exactly the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable)
      • assertOptionallyThrowsExactly

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactly​(Class<T> expectedType,
                                                                                      Executable executable,
                                                                                      String message)
        Asserts that execution of the supplied Executable throws an exception of exactly the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, String)
      • assertOptionallyThrowsExactly

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactly​(Class<T> expectedType,
                                                                                      Executable executable,
                                                                                      Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of exactly the supplied type, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The expected exception type.
        Parameters:
        expectedType - The expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, Supplier)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                       Class<? extends T> expectedType2,
                                                                       Executable executable)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                       Class<? extends T> expectedType2,
                                                                       Executable executable,
                                                                       String message)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, String)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                       Class<? extends T> expectedType2,
                                                                       Executable executable,
                                                                       Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, Supplier)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                       Executable executable)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                       Executable executable,
                                                                       String message)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, String)
      • assertThrowsExactlyOneOf

        public static <T extends Throwable> T assertThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                       Executable executable,
                                                                       Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, Supplier)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                                           Class<? extends T> expectedType2,
                                                                                           Executable executable)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                                           Class<? extends T> expectedType2,
                                                                                           Executable executable,
                                                                                           String message)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, String)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Class<? extends T> expectedType1,
                                                                                           Class<? extends T> expectedType2,
                                                                                           Executable executable,
                                                                                           Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, Supplier)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                           Executable executable)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                           Executable executable,
                                                                                           String message)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, String)
      • assertOptionallyThrowsExactlyOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsExactlyOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                           Executable executable,
                                                                                           Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of exactly one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

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

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrowsExactly(Class, Executable, Supplier)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Class<? extends T> expectedType1,
                                                                Class<? extends T> expectedType2,
                                                                Executable executable)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Class<? extends T> expectedType1,
                                                                Class<? extends T> expectedType2,
                                                                Executable executable,
                                                                String message)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, String)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Class<? extends T> expectedType1,
                                                                Class<? extends T> expectedType2,
                                                                Executable executable,
                                                                Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, Supplier)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                Executable executable)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                Executable executable,
                                                                String message)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, String)
      • assertThrowsOneOf

        public static <T extends Throwable> T assertThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                Executable executable,
                                                                Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, 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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        The exception that was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, Supplier)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Class<? extends T> expectedType1,
                                                                                    Class<? extends T> expectedType2,
                                                                                    Executable executable)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Class<? extends T> expectedType1,
                                                                                    Class<? extends T> expectedType2,
                                                                                    Executable executable,
                                                                                    String message)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, String)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Class<? extends T> expectedType1,
                                                                                    Class<? extends T> expectedType2,
                                                                                    Executable executable,
                                                                                    Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedType1 - The first expected exception type to check for.
        expectedType2 - The second expected exception type to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, Supplier)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                    Executable executable)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                    Executable executable,
                                                                                    String message)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        message - The failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, String)
      • assertOptionallyThrowsOneOf

        public static <T extends ThrowableOptional<T> assertOptionallyThrowsOneOf​(Collection<Class<? extends T>> expectedTypes,
                                                                                    Executable executable,
                                                                                    Supplier<String> messageSupplier)
        Asserts that execution of the supplied Executable throws an exception of one of the supplied types, or throws nothing at all. If an exception was thrown, it is returned.

        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, ignore the return value.

        Type Parameters:
        T - The common super type of the expected exception types.
        Parameters:
        expectedTypes - The expected exception types to check for.
        executable - The Executable to run.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        An Optional describing the exception that was thrown, or Optional.empty() if no exception was thrown.
        See Also:
        Assertions.assertThrows(Class, Executable, Supplier)
      • assertDoesNotThrowCheckedException

        public static void assertDoesNotThrowCheckedException​(Executable executable)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(Executable), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Parameters:
        executable - The piece of code that should not throw a checked exception.
      • assertDoesNotThrowCheckedException

        public static void assertDoesNotThrowCheckedException​(Executable executable,
                                                              String message)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(Executable, String), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Parameters:
        executable - The piece of code that should not throw a checked exception.
        message - The failure message to fail with.
      • assertDoesNotThrowCheckedException

        public static void assertDoesNotThrowCheckedException​(Executable executable,
                                                              Supplier<String> messageSupplier)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(Executable, Supplier), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Parameters:
        executable - The piece of code that should not throw a checked exception.
        messageSupplier - The supplier for the failure message to fail with.
      • assertDoesNotThrowCheckedException

        public static <T> T assertDoesNotThrowCheckedException​(ThrowingSupplier<T> supplier)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(ThrowingSupplier), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Type Parameters:
        T - The type of results supplied by the given supplier.
        Parameters:
        supplier - The piece of code that should not throw a checked exception.
        Returns:
        A result supplied by the given supplier.
      • assertDoesNotThrowCheckedException

        public static <T> T assertDoesNotThrowCheckedException​(ThrowingSupplier<T> supplier,
                                                               String message)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(ThrowingSupplier, String), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Type Parameters:
        T - The type of results supplied by the given supplier.
        Parameters:
        supplier - The piece of code that should not throw a checked exception.
        message - The failure message to fail with.
        Returns:
        A result supplied by the given supplier.
      • assertDoesNotThrowCheckedException

        public static <T> T assertDoesNotThrowCheckedException​(ThrowingSupplier<T> supplier,
                                                               Supplier<String> messageSupplier)
        Asserts that a piece of code does not throw a checked exception. This method works a lot like Assertions.assertDoesNotThrow(ThrowingSupplier, Supplier), except any error or unchecked exception will not be caught. It allows failed assertion errors to pass through.
        Type Parameters:
        T - The type of results supplied by the given supplier.
        Parameters:
        supplier - The piece of code that should not throw a checked exception.
        messageSupplier - The supplier for the failure message to fail with.
        Returns:
        A result supplied by the given supplier.
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.

        This method uses a maximum depth of 20. To use a different maximum length, use assertChainEquals(Throwable, Throwable, int).

        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Since:
        2.2
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual,
                                                  int maxDepth)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.
        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        maxDepth - The maximum depth, defined as the maximum number of causes to traverse.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Throws:
        IllegalArgumentException - If the given maximum depth is negative.
        Since:
        2.2
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual,
                                                  String message)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.

        This method uses a maximum depth of 20. To use a different maximum length, use assertChainEquals(Throwable, Throwable, int, String).

        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        message - The failure message to fail with.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Since:
        2.2
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual,
                                                  int maxDepth,
                                                  String message)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.
        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        maxDepth - The maximum depth, defined as the maximum number of causes to traverse.
        message - The failure message to fail with.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Throws:
        IllegalArgumentException - If the given maximum depth is negative.
        Since:
        2.2
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual,
                                                  Supplier<String> messageSupplier)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.

        This method uses a maximum depth of 20. To use a different maximum length, use assertChainEquals(Throwable, Throwable, int, Supplier).

        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        messageSupplier - The supplier for the failure message to fail with. It takes the depth at which the failure occurs as argument.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Since:
        2.2
      • assertChainEquals

        public static Throwable assertChainEquals​(Throwable expected,
                                                  Throwable actual,
                                                  int maxDepth,
                                                  Supplier<String> messageSupplier)
        Asserts that a throwable represents the same throwable chain as another. Two throwable chains are regarded as equal if they have the same throwables in the chain, where equality is determined by the type and message.
        Parameters:
        expected - The throwable with the expected throwable chain.
        actual - The actual throwable.
        maxDepth - The maximum depth, defined as the maximum number of causes to traverse.
        messageSupplier - The supplier for the failure message to fail with. It takes the depth at which the failure occurs as argument.
        Returns:
        The first cause of the actual throwable that exceeds the maximum depth, or null if the actual throwable chain does not exceed the maximum depth.
        Throws:
        IllegalArgumentException - If the given maximum depth is negative.
        Since:
        2.2