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:
- 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 aTestAbortedException(which Jupiter treats as a skip, not a failure). - If the test itself throws an exception that looks like a network failure (
ConnectException,UnknownHostException,SocketTimeoutException,SSLException, or HTTP 5xx wrapped inIOException), convert it into aTestAbortedExceptionso the test is skipped rather than failed.
- Author:
- poirigui
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext ctx) voidhandleTestExecutionException(org.junit.jupiter.api.extension.ExtensionContext ctx, Throwable t)
-
Constructor Details
-
NetworkAvailableExtension
public NetworkAvailableExtension()
-
-
Method Details
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext ctx) - Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
handleTestExecutionException
-