Skip to content

Instantly share code, notes, and snippets.

@eduardocl
Created April 26, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardocl/270a54e97eaf2ecff0cc84ea7406f50b to your computer and use it in GitHub Desktop.
Save eduardocl/270a54e97eaf2ecff0cc84ea7406f50b to your computer and use it in GitHub Desktop.
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
public class ECLRunner extends BlockJUnit4ClassRunner {
private Integer testsLeft;
public ECLRunner(Class<?> testClass) throws InitializationError {
super(testClass);
this.testsLeft = this.testCount();
}
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
super.runChild(method, notifier);
if (--this.testsLeft == 0) {
this.shutdown();
}
}
@Override
public void run(RunNotifier notifier) {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
this.startup(container);
super.run(notifier);
weld.shutdown();
}
protected Object createTest() throws Exception {
return Beans.getReference(getTestClass().getJavaClass());
}
private void startup(WeldContainer container) {
Beans.setBeanManager(container.getBeanManager());
Beans.getBeanManager().fireEvent(new Object() {
});
}
private void shutdown() {
Beans.getBeanManager().fireEvent(new Object() {
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment