Class SystemExitExtension

java.lang.Object
com.ginsberg.junit.exit.SystemExitExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestExecutionExceptionHandler

public class SystemExitExtension extends Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.TestExecutionExceptionHandler
Entry point for JUnit tests. This class is responsible for installing the preferred `ExitPreventerStrategy` and interpreting the results.
  • Constructor Details

    • SystemExitExtension

      public SystemExitExtension()
  • Method Details

    • afterEach

      public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterEach in interface org.junit.jupiter.api.extension.AfterEachCallback
    • beforeEach

      public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallback
    • handleTestExecutionException

      public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext context, Throwable throwable) throws Throwable
      This is here so we can catch exceptions thrown by the `ExitPreventerStrategy` and prevent them from stopping the annotated test. If anything other than our own exception comes through, throw it because the `ExitPreventerStrategy` has encountered some other test-failing exception.
      Specified by:
      handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
      Parameters:
      context - the current extension context; never null
      throwable - the Throwable to handle; never null
      Throws:
      Throwable - if the throwable argument is not a SystemExitPreventedException