Class ExpectedExceptionSupport

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestExecutionExceptionHandler

    @API(status=STABLE,
         since="5.7")
    public class ExpectedExceptionSupport
    extends java.lang.Object
    implements org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.TestExecutionExceptionHandler
    This Extension provides native support for the ExpectedException rule from JUnit 4.

    By using this class-level extension on a test class, ExpectedException can continue to be used.

    However, you should rather switch to Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable) for new code.

    Since:
    5.0
    See Also:
    Assertions.assertThrows(java.lang.Class<T>, org.junit.jupiter.api.function.Executable), ExpectedException, TestRule, Rule
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      private org.junit.jupiter.api.extension.ExtensionContext.Store getStore​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void handleTestExecutionException​(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Throwable throwable)  
      • Methods inherited from class java.lang.Object

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

      • ExpectedExceptionSupport

        public ExpectedExceptionSupport()
    • Method Detail

      • handleTestExecutionException

        public void handleTestExecutionException​(org.junit.jupiter.api.extension.ExtensionContext context,
                                                 java.lang.Throwable throwable)
                                          throws java.lang.Throwable
        Specified by:
        handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
        Throws:
        java.lang.Throwable
      • afterEach

        public void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)
                       throws java.lang.Exception
        Specified by:
        afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
        Throws:
        java.lang.Exception
      • getStore

        private org.junit.jupiter.api.extension.ExtensionContext.Store getStore​(org.junit.jupiter.api.extension.ExtensionContext context)