Class Asserts


  • @Deprecated(forRemoval=true)
    public final class Asserts
    extends Object
    Deprecated, for removal: This API element is subject to removal in a future version.
    JUnit 4.13 ships with a working assertThrows(Class, JUnitExecutable), so there is no point shipping this class.
    Assert extension for JUnit.

    Including some JUnit v5 NG APIs for JUnit 4 already.

    • Method Detail

      • assertThrows

        @Deprecated(forRemoval=true)
        public static <T extends Throwable> T assertThrows​(Class<T> expectedThrowable,
                                                           Asserts.JUnitExecutable exec)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use Assert.assertThrows(Class, org.junit.function.ThrowingRunnable) instead.
        Asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception.

        This is useful to avoid (and comply with) Error Prone's TestExceptionChecker bug pattern.

        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.

        Back-ported from org.junit.jupiter.api.Assertions.