Interface ResourceLocksProvider


@API(status=EXPERIMENTAL, since="5.12") public interface ResourceLocksProvider
A ResourceLocksProvider is used to programmatically add shared resources to a test class or its test methods dynamically at runtime.

Each shared resource is represented by an instance of ResourceLocksProvider.Lock.

Adding shared resources via this API has the same semantics as declaring them declaratively via @ResourceLock(value, mode), but for some use cases the programmatic approach may be more flexible and less verbose.

Implementations must provide a no-args constructor.

Since:
5.12
See Also:
  • Method Details

    • provideForClass

      default Set<ResourceLocksProvider.Lock> provideForClass(Class<?> testClass)
      Add shared resources for a test class.

      Invoked in case a test class or its parent class is annotated with @ResourceLock(providers).

      Parameters:
      testClass - a test class for which to add shared resources
      Returns:
      a set of ResourceLocksProvider.Lock; may be empty
      API Note:
      Adding a shared resource via this method has the same semantics as annotating a test class with an analogous @ResourceLock(value, mode) declaration.
    • provideForNestedClass

      default Set<ResourceLocksProvider.Lock> provideForNestedClass(List<Class<?>> enclosingInstanceTypes, Class<?> testClass)
      Add shared resources for a @Nested test class.

      Invoked in case:

      • an enclosing test class of any level or its parent class is annotated with @ResourceLock(providers = ...).
      • a nested test class or its parent class is annotated with @ResourceLock(providers = ...).
      Parameters:
      enclosingInstanceTypes - the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null
      testClass - a nested test class for which to add shared resources
      Returns:
      a set of ResourceLocksProvider.Lock; may be empty
      See Also:
      API Note:
      Adding a shared resource via this method has the same semantics as annotating a nested test class with an analogous @ResourceLock(value, mode) declaration.
      Implementation Note:
      The classes supplied as enclosingInstanceTypes may differ from the classes returned from invocations of Class.getEnclosingClass() — for example, when a nested test class is inherited from a superclass.
    • provideForMethod

      default Set<ResourceLocksProvider.Lock> provideForMethod(List<Class<?>> enclosingInstanceTypes, Class<?> testClass, Method testMethod)
      Add shared resources for a test method.

      Invoked in case:

      • an enclosing test class of any level or its parent class is annotated with @ResourceLock(providers).
      • a test method is annotated with @ResourceLock(providers).
      Parameters:
      enclosingInstanceTypes - the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null
      testClass - the test class or @Nested test class that contains the testMethod
      testMethod - a test method for which to add shared resources
      Returns:
      a set of ResourceLocksProvider.Lock; may be empty
      See Also:
      API Note:
      Adding a shared resource with this method has the same semantics as annotating a test method with analogous @ResourceLock(value, mode).
      Implementation Note:
      The classes supplied as enclosingInstanceTypes may differ from the classes returned from invocations of Class.getEnclosingClass() — for example, when a nested test class is inherited from a superclass. Similarly, the class instance supplied as testClass may differ from the class returned by testMethod.getDeclaringClass() — for example, when a test method is inherited from a superclass.