Merge branch '1.4.x' into 1.5.x
This commit is contained in:
commit
ac05b61df9
|
|
@ -79,6 +79,19 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object createTest() throws Exception {
|
||||||
|
FilteredTestClass testClass = (FilteredTestClass) getTestClass();
|
||||||
|
return testClass.doWithFilteredContextClassLoader(
|
||||||
|
new FilteredTestClass.FilteredTcclAction<Object, Exception>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object perform() throws Exception {
|
||||||
|
return ModifiedClassPathRunner.super.createTest();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private URLClassLoader createTestClassLoader(Class<?> testClass) throws Exception {
|
private URLClassLoader createTestClassLoader(Class<?> testClass) throws Exception {
|
||||||
URLClassLoader classLoader = (URLClassLoader) this.getClass().getClassLoader();
|
URLClassLoader classLoader = (URLClassLoader) this.getClass().getClassLoader();
|
||||||
return new FilteredClassLoader(processUrls(extractUrls(classLoader), testClass),
|
return new FilteredClassLoader(processUrls(extractUrls(classLoader), testClass),
|
||||||
|
|
@ -246,40 +259,60 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||||
List<FrameworkMethod> wrapped = new ArrayList<FrameworkMethod>(
|
List<FrameworkMethod> wrapped = new ArrayList<FrameworkMethod>(
|
||||||
methods.size());
|
methods.size());
|
||||||
for (FrameworkMethod frameworkMethod : methods) {
|
for (FrameworkMethod frameworkMethod : methods) {
|
||||||
wrapped.add(new FilteredFrameworkMethod(this.classLoader,
|
wrapped.add(new FilteredFrameworkMethod(frameworkMethod.getMethod()));
|
||||||
frameworkMethod.getMethod()));
|
|
||||||
}
|
}
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
private <T, E extends Throwable> T doWithFilteredContextClassLoader(
|
||||||
|
FilteredTcclAction<T, E> action) throws E {
|
||||||
/**
|
|
||||||
* Filtered version of JUnit's {@link FrameworkMethod}.
|
|
||||||
*/
|
|
||||||
private static final class FilteredFrameworkMethod extends FrameworkMethod {
|
|
||||||
|
|
||||||
private final ClassLoader classLoader;
|
|
||||||
|
|
||||||
private FilteredFrameworkMethod(ClassLoader classLoader, Method method) {
|
|
||||||
super(method);
|
|
||||||
this.classLoader = classLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object invokeExplosively(Object target, Object... params)
|
|
||||||
throws Throwable {
|
|
||||||
ClassLoader originalClassLoader = Thread.currentThread()
|
ClassLoader originalClassLoader = Thread.currentThread()
|
||||||
.getContextClassLoader();
|
.getContextClassLoader();
|
||||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||||
try {
|
try {
|
||||||
return super.invokeExplosively(target, params);
|
return action.perform();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Thread.currentThread().setContextClassLoader(originalClassLoader);
|
Thread.currentThread().setContextClassLoader(originalClassLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An action to be performed with the {@link FilteredClassLoader} set as the
|
||||||
|
* thread context class loader.
|
||||||
|
*/
|
||||||
|
private interface FilteredTcclAction<T, E extends Throwable> {
|
||||||
|
|
||||||
|
T perform() throws E;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filtered version of JUnit's {@link FrameworkMethod}.
|
||||||
|
*/
|
||||||
|
private final class FilteredFrameworkMethod extends FrameworkMethod {
|
||||||
|
|
||||||
|
private FilteredFrameworkMethod(Method method) {
|
||||||
|
super(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invokeExplosively(final Object target, final Object... params)
|
||||||
|
throws Throwable {
|
||||||
|
return doWithFilteredContextClassLoader(
|
||||||
|
new FilteredTcclAction<Object, Throwable>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object perform() throws Throwable {
|
||||||
|
return FilteredFrameworkMethod.super.invokeExplosively(
|
||||||
|
target, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class FilteredClassLoader extends URLClassLoader {
|
private static final class FilteredClassLoader extends URLClassLoader {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue