我之前问过如何使线程池中的单元测试失败。
@Test
public void foo() throws Exception {
ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(1);
stpe.submit(new Runnable() {
@Override
public void run() {
// does not make this unit test fail :(
Assert.AssertEquals(1, 2);
}
});
}
我接受的解决方案是阻止返回Future
并获取。但在我的实际设置中,我既不拥有线程池也不拥有提交调用——它是一个最终源自 MINA 的回调。
关于我最好的想法是搞乱全局默认异常处理程序,但看起来很笨拙。
Maven 万无一失。