![JAR search and dependency download from the Maven repository](/logo.png)
org.alfresco.mock.ClasspathTestRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alfresco-tests Show documentation
Show all versions of alfresco-tests Show documentation
This is a jar project based on mock classes to test fastly the alfresco applications
The newest version!
package org.alfresco.mock;
import static java.lang.Class.forName;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class ClasspathTestRunner extends SpringJUnit4ClassRunner {
static ClassLoader customClassLoader;
public ClasspathTestRunner(Class> clazz) throws InitializationError {
super(loadFromCustomClassloader(clazz));
}
// Loads a class in the custom classloader
private static Class> loadFromCustomClassloader(Class> clazz) throws InitializationError {
try {
// Only load once to support parallel tests
if (customClassLoader == null) {
customClassLoader = new ModuleClassLoader();
}
return forName(clazz.getName(), true, customClassLoader);
} catch (ClassNotFoundException e) {
throw new InitializationError(e);
}
}
// Runs junit tests in a separate thread using the custom class loader
@Override
public void run(final RunNotifier notifier) {
Runnable runnable = () -> {
super.run(notifier);
};
Thread thread = new Thread(runnable);
thread.setContextClassLoader(customClassLoader);
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy