Class ExpectedExceptionExtension

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

    class ExpectedExceptionExtension
    extends java.lang.Object
    implements org.junit.jupiter.api.extension.TestExecutionExceptionHandler, org.junit.jupiter.api.extension.AfterTestExecutionCallback
    This extension implements the expected exception behavior of @Test, where a test only passes if it throws an exception of the specified type.
    • Field Detail

      • EXPECTED_EXCEPTION_WAS_NOT_THROWN

        static final java.lang.String EXPECTED_EXCEPTION_WAS_NOT_THROWN
        See Also:
        Constant Field Values
      • NAMESPACE

        private static final org.junit.jupiter.api.extension.ExtensionContext.Namespace NAMESPACE
    • Constructor Detail

      • ExpectedExceptionExtension

        ExpectedExceptionExtension()
    • 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
      • afterTestExecution

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

        private static java.util.Optional<? extends java.lang.Class<? extends java.lang.Throwable>> expectedException​(org.junit.jupiter.api.extension.ExtensionContext context)