-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix using resource locks on test templates
Prior to this commit, it was not possible to use `@ResourceLock` on `@TestTemplate` methods because `TestTemplateInvocationTestDescriptor` returned a non-empty set of `ExclusiveResources` which is disallowed for dynamically added `TestDescriptors`. Now, an empty set is returned instead which works because the parent `TestTemplateTestDescriptor` returns the resources from the `@ResourceLock` annotation. Fixes #1697.
- Loading branch information
1 parent
fe1993e
commit 60f3125
Showing
6 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...t/java/org/junit/jupiter/engine/descriptor/TestTemplateInvocationTestDescriptorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2015-2018 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.engine.descriptor; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.anyInt; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext; | ||
import org.junit.jupiter.api.parallel.ResourceLock; | ||
import org.junit.jupiter.engine.config.JupiterConfiguration; | ||
import org.junit.platform.engine.UniqueId; | ||
|
||
class TestTemplateInvocationTestDescriptorTests { | ||
|
||
@Test | ||
void invocationsDoNotDeclareExclusiveResources() throws Exception { | ||
Class<MyTestCase> testClass = MyTestCase.class; | ||
Method testTemplateMethod = testClass.getDeclaredMethod("testTemplate"); | ||
JupiterConfiguration configuration = mock(JupiterConfiguration.class); | ||
TestTemplateTestDescriptor parent = new TestTemplateTestDescriptor(UniqueId.root("segment", "template"), | ||
testClass, testTemplateMethod, configuration); | ||
TestTemplateInvocationContext invocationContext = mock(TestTemplateInvocationContext.class); | ||
when(invocationContext.getDisplayName(anyInt())).thenReturn("invocation"); | ||
|
||
TestTemplateInvocationTestDescriptor testDescriptor = new TestTemplateInvocationTestDescriptor( | ||
parent.getUniqueId().append(TestTemplateInvocationTestDescriptor.SEGMENT_TYPE, "1"), testClass, | ||
testTemplateMethod, invocationContext, 1, configuration); | ||
|
||
assertThat(parent.getExclusiveResources()).hasSize(1); | ||
assertThat(testDescriptor.getExclusiveResources()).isEmpty(); | ||
} | ||
|
||
static class MyTestCase { | ||
@TestTemplate | ||
@ResourceLock("a") | ||
void testTemplate() { | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters