Class NetworkAvailableExtension

java.lang.Object
ubic.gemma.core.util.test.NetworkAvailableExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestExecutionExceptionHandler

public class NetworkAvailableExtension extends Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.TestExecutionExceptionHandler
Enables the NetworkAvailable annotation on JUnit 5 tests.

Two-phase behaviour:

  1. Before each test, for every URL declared via @NetworkAvailable(url=...) on the test class or method, attempt a short-timeout connection. If the resource is unreachable, abort the test with a TestAbortedException (which Jupiter treats as a skip, not a failure).
  2. If the test itself throws an exception that looks like a network failure (ConnectException, UnknownHostException, SocketTimeoutException, SSLException, or HTTP 5xx wrapped in IOException), convert it into a TestAbortedException so the test is skipped rather than failed.
Per-URL outcomes are cached statically so the connection check runs at most once per URL per JVM.
Author:
poirigui
See Also:
  • Constructor Details

    • NetworkAvailableExtension

      public NetworkAvailableExtension()
  • Method Details

    • beforeEach

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

      public void handleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext ctx, Throwable t) throws Throwable
      Specified by:
      handleTestExecutionException in interface org.junit.jupiter.api.extension.TestExecutionExceptionHandler
      Throws:
      Throwable