Top Description Inners Methods
org.junit.jupiter.api.parallel

public Interface ResourceLocksProvider

Annotations
@API
status:MAINTAINED
since:5.13.3
Static Imports
java.util.Collections.emptySet, org.apiguardian.api.API.Status.MAINTAINED

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 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
ResourceLock#providers(), Resources, ResourceAccessMode, Lock

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ResourceLocksProvider.Lock

Lock represents a shared resource.

Method Summary

Modifier and TypeMethod and Description
public default Set<ResourceLocksProvider.Lock>

Returns:

a set of Lock; may be empty
provideForClass
(Class<?>
a test class for which to add shared resources
testClass
)

Add shared resources for a test class.

public default Set<ResourceLocksProvider.Lock>

Returns:

a set of Lock; may be empty
provideForMethod
(List<Class<?>>
the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null
enclosingInstanceTypes
,
Class<?>
the test class or @Nested test class that contains the testMethod
testClass
,
Method
a test method for which to add shared resources
testMethod
)

Add shared resources for a test method.

public default Set<ResourceLocksProvider.Lock>

Returns:

a set of Lock; may be empty
provideForNestedClass
(List<Class<?>>
the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null
enclosingInstanceTypes
,
Class<?>
a nested test class for which to add shared resources
testClass
)

Add shared resources for a @Nested test class.

Method Detail

provideForClassback to summary
public 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).

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.

Parameters
testClass:Class<?>

a test class for which to add shared resources

Returns:Set<ResourceLocksProvider.Lock>

a set of Lock; may be empty

provideForMethodback to summary
public 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).

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.

Parameters
enclosingInstanceTypes:List<Class<?>>

the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null

testClass:Class<?>

the test class or @Nested test class that contains the testMethod

testMethod:Method

a test method for which to add shared resources

Returns:Set<ResourceLocksProvider.Lock>

a set of Lock; may be empty

See Also
@Nested
provideForNestedClassback to summary
public 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 = ...).

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.

Parameters
enclosingInstanceTypes:List<Class<?>>

the runtime types of the enclosing instances for the test class, ordered from outermost to innermost, excluding testClass; never null

testClass:Class<?>

a nested test class for which to add shared resources

Returns:Set<ResourceLocksProvider.Lock>

a set of Lock; may be empty

See Also
@Nested
org.junit.jupiter.api.parallel back to summary

public final Class ResourceLocksProvider.Lock

extends Object
Class Inheritance

Lock represents a shared resource.

Each resource is identified by a key. In addition, the access mode allows one to specify whether a test class or test method requires READ_WRITE or READ access to the resource.

API Note

getKey() and getAccessMode() have the same semantics as ResourceLock#value() and ResourceLock#mode() respectively.

Since
5.12
See Also
Isolated, Resources, ResourceAccessMode, ResourceLock, ResourceLocksProvider

Field Summary

Modifier and TypeField and Description
private final ResourceAccessMode
private final String

Constructor Summary

AccessConstructor and Description
public
Lock(String
the identifier of the resource; never null or blank
key
)

Create a new Lock with ResourceAccessMode#READ_WRITE.

public
Lock(String
the identifier of the resource; never null or blank
key
,
ResourceAccessMode
the lock mode to use to synchronize access to the resource; never null
accessMode
)

Create a new Lock.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public ResourceAccessMode
getAccessMode()

Get the access mode for this lock.

public String
getKey()

Get the key for this lock.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

accessModeback to summary
private final ResourceAccessMode accessMode
keyback to summary
private final String key

Constructor Detail

Lockback to summary
public Lock(String key)

Create a new Lock with ResourceAccessMode#READ_WRITE.

Parameters
key:String

the identifier of the resource; never null or blank

See Also
ResourceLock#value()
Lockback to summary
public Lock(String key, ResourceAccessMode accessMode)

Create a new Lock.

Parameters
key:String

the identifier of the resource; never null or blank

accessMode:ResourceAccessMode

the lock mode to use to synchronize access to the resource; never null

See Also
ResourceLock#value(), ResourceLock#mode()

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getAccessModeback to summary
public ResourceAccessMode getAccessMode()

Get the access mode for this lock.

See Also
ResourceLock#mode()
getKeyback to summary
public String getKey()

Get the key for this lock.

See Also
ResourceLock#value()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override