Class SyncAsyncExtension

java.lang.Object
com.azure.core.test.SyncAsyncExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider

public final class SyncAsyncExtension extends Object implements org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
An test template extension that helps to branch out a single test into sync and async invocation.
  • Constructor Details

    • SyncAsyncExtension

      public SyncAsyncExtension()
  • Method Details

    • execute

      public static <T> T execute(Callable<T> sync, Callable<Mono<T>> async)
      Executes sync or async branch depending on the context.
      Type Parameters:
      T - type of result of either sync or async invocation.
      Parameters:
      sync - sync callable.
      async - async callable. It should block at some point to return result.
      Returns:
      result of either sync or async invocation.
      Throws:
      IllegalStateException - if extension doesn't work as expected.
      RuntimeException - a runtime exception wrapping error from callable.
    • execute

      public static void execute(Runnable sync, Callable<Mono<Void>> async)
      Executes sync or async branch depending on the context.
      Parameters:
      sync - sync callable.
      async - async callable. It should block at some point to return result.
      Throws:
      IllegalStateException - if extension doesn't work as expected.
      RuntimeException - a runtime exception wrapping error from callable.
    • supportsTestTemplate

      public boolean supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
      Specified by:
      supportsTestTemplate in interface org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider
    • provideTestTemplateInvocationContexts

      public Stream<org.junit.jupiter.api.extension.TestTemplateInvocationContext> provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
      Specified by:
      provideTestTemplateInvocationContexts in interface org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider