diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java index 53d278918aba..d8ccda001ba1 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptor.java @@ -188,17 +188,18 @@ public static ExecutionMode toExecutionMode(org.junit.jupiter.api.parallel.Execu Set getExclusiveResourcesFromAnnotation(AnnotatedElement element, Function> providerToLocks) { + List resourceLocks = findRepeatableAnnotations(element, ResourceLock.class); // @formatter:off return Stream.concat( - getExclusiveResourcesFromAnnotationValue(element), - getExclusiveResourcesFromAnnotationProviders(element, providerToLocks) + getExclusiveResourcesFromValues(resourceLocks), + getExclusiveResourcesFromProviders(resourceLocks, providerToLocks) ).collect(collectingAndThen(toSet(), Collections::unmodifiableSet)); // @formatter:on } - Stream getExclusiveResourcesFromAnnotationValue(AnnotatedElement element) { + Stream getExclusiveResourcesFromValues(List resourceLocks) { // @formatter:off - return findRepeatableAnnotations(element, ResourceLock.class).stream() + return resourceLocks.stream() .flatMap(resourceLock -> { if (StringUtils.isBlank(resourceLock.value())) { return Stream.empty(); @@ -208,10 +209,10 @@ Stream getExclusiveResourcesFromAnnotationValue(AnnotatedElem // @formatter:on } - Stream getExclusiveResourcesFromAnnotationProviders(AnnotatedElement element, + Stream getExclusiveResourcesFromProviders(List resourceLocks, Function> providerToLocks) { // @formatter:off - return findRepeatableAnnotations(element, ResourceLock.class).stream() + return resourceLocks.stream() .flatMap(resourceLock -> Stream.of(resourceLock.providers()) .map(ReflectionUtils::newInstance) .map(providerToLocks) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java index 6a8ad8ddee9c..645c71ddfd8d 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java @@ -14,6 +14,7 @@ import static java.util.stream.Collectors.toSet; import static org.apiguardian.api.API.Status.INTERNAL; import static org.junit.jupiter.engine.descriptor.DisplayNameUtils.determineDisplayNameForMethod; +import static org.junit.platform.commons.support.AnnotationSupport.findRepeatableAnnotations; import static org.junit.platform.commons.util.CollectionUtils.forEachInReverseOrder; import java.lang.reflect.Method; @@ -29,6 +30,7 @@ import org.apiguardian.api.API; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.TestWatcher; +import org.junit.jupiter.api.parallel.ResourceLock; import org.junit.jupiter.api.parallel.ResourceLocksProvider; import org.junit.jupiter.engine.config.JupiterConfiguration; import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext; @@ -91,18 +93,18 @@ public Set getExclusiveResources() { Function> providerToLocks = p -> p.provideForMethod(getTestClass(), getTestMethod()); - Set fromMethodLevelAnnotation = getExclusiveResourcesFromAnnotation( + Set fromMethodAnnotation = getExclusiveResourcesFromAnnotation( getTestMethod(), providerToLocks ); - Stream fromProvidersInClassLevelAnnotation = getExclusiveResourcesFromAnnotationProviders( - getTestClass(), + Stream fromProvidersInClassAnnotation = getExclusiveResourcesFromProviders( + findRepeatableAnnotations(getTestClass(), ResourceLock.class), providerToLocks ); return Stream.concat( - fromMethodLevelAnnotation.stream(), - fromProvidersInClassLevelAnnotation + fromMethodAnnotation.stream(), + fromProvidersInClassAnnotation ).collect(collectingAndThen(toSet(), Collections::unmodifiableSet)); // @formatter:on }