我需要为此测试InterruptedException
和ExecutionException
编写 JUnit。
请就此给我建议。我如何中断线程来复制场景。将populateDataForm
启动新线程并将其添加到期货列表中。
这是我的示例代码:
class MyTest{
public populateData(){
Collection<Future<?>> futures = new LinkedList<Future<?>>();
DataSet ds = Helper.populateDataForm(employee, futures);
waitForTaskCompletion(futures);
}
private waitForTaskCompletion(futures){
for (Future<?> future:futures) {
try {
future.get();
} catch (InterruptedException e) {
throw new CustomExcpetion("Message1", e)
} catch (ExecutionException e) {
throw new CustomExcpetion("Message2", e)
}
}
}