|
12 | 12 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; |
13 | 13 | import org.junit.jupiter.api.extension.ExtensionContext.Store; |
14 | 14 | import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource; |
15 | | -import org.junit.jupiter.api.extension.TestInstancePostProcessor; |
16 | 15 | import org.junit.platform.commons.support.AnnotationSupport; |
17 | 16 | import org.junit.platform.commons.util.AnnotationUtils; |
18 | 17 | import org.junit.platform.commons.util.Preconditions; |
|
23 | 22 | import org.testcontainers.lifecycle.TestLifecycleAware; |
24 | 23 |
|
25 | 24 | import java.lang.reflect.Field; |
26 | | -import java.lang.reflect.Method; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Collections; |
27 | 27 | import java.util.LinkedHashSet; |
28 | 28 | import java.util.List; |
29 | 29 | import java.util.Optional; |
|
34 | 34 | import static java.util.stream.Collectors.toList; |
35 | 35 | import static org.testcontainers.junit.jupiter.FilesystemFriendlyNameGenerator.filesystemFriendlyNameOf; |
36 | 36 |
|
37 | | -class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback, ExecutionCondition, TestInstancePostProcessor { |
| 37 | +class TestcontainersExtension implements BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback, ExecutionCondition { |
38 | 38 |
|
39 | 39 | private static final Namespace NAMESPACE = Namespace.create(TestcontainersExtension.class); |
40 | 40 |
|
41 | | - private static final String TEST_INSTANCE = "testInstance"; |
42 | 41 | private static final String SHARED_LIFECYCLE_AWARE_CONTAINERS = "sharedLifecycleAwareContainers"; |
43 | 42 | private static final String LOCAL_LIFECYCLE_AWARE_CONTAINERS = "localLifecycleAwareContainers"; |
44 | 43 |
|
45 | | - @Override |
46 | | - public void postProcessTestInstance(final Object testInstance, final ExtensionContext context) { |
47 | | - Store store = context.getStore(NAMESPACE); |
48 | | - store.put(TEST_INSTANCE, testInstance); |
49 | | - } |
50 | | - |
51 | 44 | @Override |
52 | 45 | public void beforeAll(ExtensionContext context) { |
53 | 46 | Class<?> testClass = context.getTestClass() |
@@ -156,17 +149,9 @@ boolean isDockerAvailable() { |
156 | 149 | } |
157 | 150 |
|
158 | 151 | private Set<Object> collectParentTestInstances(final ExtensionContext context) { |
159 | | - Set<Object> testInstances = new LinkedHashSet<>(); |
160 | | - Optional<ExtensionContext> current = Optional.of(context); |
161 | | - while (current.isPresent()) { |
162 | | - ExtensionContext ctx = current.get(); |
163 | | - Object testInstance = ctx.getStore(NAMESPACE).remove(TEST_INSTANCE); |
164 | | - if (testInstance != null) { |
165 | | - testInstances.add(testInstance); |
166 | | - } |
167 | | - current = ctx.getParent(); |
168 | | - } |
169 | | - return testInstances; |
| 152 | + List<Object> allInstances = new ArrayList<>(context.getRequiredTestInstances().getAllInstances()); |
| 153 | + Collections.reverse(allInstances); |
| 154 | + return new LinkedHashSet<>(allInstances); |
170 | 155 | } |
171 | 156 |
|
172 | 157 | private List<StoreAdapter> findSharedContainers(Class<?> testClass) { |
|
0 commit comments