|
|
|
|
@ -69,7 +69,7 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
@@ -69,7 +69,7 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
|
|
|
|
|
.addPackage(testMethod.getDeclaringClass().getPackage(), withPackageResources.value())); |
|
|
|
|
ResourcesClassLoader classLoader = new ResourcesClassLoader(context.getRequiredTestClass().getClassLoader(), |
|
|
|
|
resources); |
|
|
|
|
store.put(TCCL_KEY, Thread.currentThread().getContextClassLoader()); |
|
|
|
|
store.put(TCCL_KEY, new Tccl()); |
|
|
|
|
Thread.currentThread().setContextClassLoader(classLoader); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -105,7 +105,7 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
@@ -105,7 +105,7 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
|
|
|
|
|
public void afterEach(ExtensionContext context) throws Exception { |
|
|
|
|
Store store = context.getStore(Namespace.create(ResourcesExtension.class)); |
|
|
|
|
store.get(RESOURCES_KEY, Resources.class).delete(); |
|
|
|
|
Thread.currentThread().setContextClassLoader(store.get(TCCL_KEY, ClassLoader.class)); |
|
|
|
|
Thread.currentThread().setContextClassLoader(store.get(TCCL_KEY, Tccl.class).get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -183,4 +183,23 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
@@ -183,4 +183,23 @@ class ResourcesExtension implements BeforeEachCallback, AfterEachCallback, Param
|
|
|
|
|
return resources; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Holder for the thread context class loader that can be safely |
|
|
|
|
* {@link Store#put(Object, Object) stored} without it causing unwanted |
|
|
|
|
* {@link ClassLoader#close closure} of the class loader. |
|
|
|
|
*/ |
|
|
|
|
private static class Tccl { |
|
|
|
|
|
|
|
|
|
private final ClassLoader classLoader; |
|
|
|
|
|
|
|
|
|
Tccl() { |
|
|
|
|
this.classLoader = Thread.currentThread().getContextClassLoader(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ClassLoader get() { |
|
|
|
|
return this.classLoader; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|