|
79 | 79 | import org.junit.jupiter.api.extension.ParameterResolutionException; |
80 | 80 | import org.junit.jupiter.api.extension.ParameterResolver; |
81 | 81 | import org.junit.jupiter.api.extension.RegisterExtension; |
| 82 | +import org.junit.jupiter.api.parallel.ResourceLock; |
82 | 83 | import org.junit.jupiter.engine.descriptor.ClassTemplateInvocationTestDescriptor; |
83 | 84 | import org.junit.jupiter.engine.descriptor.ClassTemplateTestDescriptor; |
84 | 85 | import org.junit.jupiter.engine.descriptor.ClassTestDescriptor; |
|
95 | 96 | import org.junit.platform.engine.UniqueId; |
96 | 97 | import org.junit.platform.engine.discovery.DiscoverySelectors; |
97 | 98 | import org.junit.platform.engine.reporting.ReportEntry; |
| 99 | +import org.junit.platform.engine.support.hierarchical.ExclusiveResource; |
98 | 100 | import org.junit.platform.testkit.engine.EngineExecutionResults; |
99 | 101 | import org.opentest4j.AssertionFailedError; |
100 | 102 | import org.opentest4j.TestAbortedException; |
@@ -1004,6 +1006,24 @@ void ignoresComposedAnnotations() { |
1004 | 1006 | assertThat(engineDescriptor.getDescendants()).isEmpty(); |
1005 | 1007 | } |
1006 | 1008 |
|
| 1009 | + @Test |
| 1010 | + void classTemplateWithResourceLockCollectsExclusiveResources() { |
| 1011 | + var results = discoverTestsForClass(ClassTemplateWithResourceLockTestCase.class); |
| 1012 | + var classTemplateDescriptor = (ClassTemplateTestDescriptor) getOnlyElement( |
| 1013 | + results.getEngineDescriptor().getChildren()); |
| 1014 | + |
| 1015 | + assertThat(classTemplateDescriptor.getExclusiveResources()).extracting( |
| 1016 | + ExclusiveResource::getKey).containsExactly("test-resource"); |
| 1017 | + } |
| 1018 | + |
| 1019 | + @Test |
| 1020 | + void classTemplateWithResourceLockExecutesSuccessfully() { |
| 1021 | + var results = executeTestsForClass(ClassTemplateWithResourceLockTestCase.class); |
| 1022 | + |
| 1023 | + results.testEvents().assertStatistics(stats -> stats.started(2).succeeded(2)); |
| 1024 | + results.containerEvents().assertStatistics(stats -> stats.started(4).succeeded(4)); |
| 1025 | + } |
| 1026 | + |
1007 | 1027 | // ------------------------------------------------------------------- |
1008 | 1028 |
|
1009 | 1029 | private static Stream<String> allReportEntryValues(EngineExecutionResults results) { |
@@ -1567,4 +1587,15 @@ void test() { |
1567 | 1587 | } |
1568 | 1588 | } |
1569 | 1589 |
|
| 1590 | + @SuppressWarnings("JUnitMalformedDeclaration") |
| 1591 | + @ClassTemplate |
| 1592 | + @ExtendWith(TwoInvocationsClassTemplateInvocationContextProvider.class) |
| 1593 | + @ResourceLock("test-resource") |
| 1594 | + static class ClassTemplateWithResourceLockTestCase { |
| 1595 | + @Test |
| 1596 | + void test() { |
| 1597 | + // This test verifies that @ResourceLock works with @ClassTemplate (issue #5155) |
| 1598 | + } |
| 1599 | + } |
| 1600 | + |
1570 | 1601 | } |
0 commit comments