Created
April 26, 2016 13:50
-
-
Save eduardocl/270a54e97eaf2ecff0cc84ea7406f50b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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