Source:
public void evaluate() throws Throwable { latch.setInterruptOnException(Thread.currentThread()); FutureTask<ScriptPair> scriptFuture = new FutureTask<>(scriptRunner); try { new Thread(scriptFuture).start(); try { latch.awaitPrepared(); } catch (InterruptedException e) { if (latch.hasException()) { throw latch.getException(); } else throw e; } try { statement.evaluate(); } catch (Throwable cause) { if (!latch.isFinished()) { scriptRunner.abort(); } ScriptPair scripts = null; Exception scriptFutureException = null; try { scripts = scriptFuture.get(5, SECONDS); } catch (Exception e) { scriptFutureException = e; } if (cause instanceof AssumptionViolatedException) { throw cause; } if (latch.hasException()) { if (cause instanceof InterruptedException) { throw latch.getException(); } throw cause.initCause(latch.getException()); } else { if (scriptFutureException != null) { if (scriptFutureException instanceof ExecutionException) { throw scriptFutureException.getCause().initCause(cause); } else { throw cause; } } else { try { assertEquals("Specified behavior did not match", scripts.getExpectedScript(), scripts.getObservedScript()); throw cause; } catch (ComparisonFailure f) { f.initCause(cause); throw f; } } } } String k3poSimpleName = K3poRule.class.getSimpleName(); assertTrue(format("Did you instantiate %s with a @Rule and call %s.start() or %s.finish()?", k3poSimpleName, k3poSimpleName, k3poSimpleName), latch.isStartable()); ScriptPair scripts = scriptFuture.get(); assertEquals("Specified behavior did not match", scripts.getExpectedScript(), scripts.getObservedScript()); } finally { try { scriptRunner.dispose(); } finally { scriptFuture.cancel(true); Thread.interrupted(); } } }

Target:
public void evaluate() throws Throwable { latch.setInterruptOnException(Thread.currentThread()); FutureTask<ScriptPair> scriptFuture = new FutureTask<>(scriptRunner); try { new Thread(scriptFuture).start(); try { latch.awaitPrepared(); } catch (InterruptedException e) { if (latch.hasException()) { throw latch.getException(); } throw e; } try { statement.evaluate(); } catch (Exception cause) { if (!latch.isFinished()) { scriptRunner.abort(); } ScriptPair scripts = null; Exception scriptFutureException = null; try { scripts = scriptFuture.get(5, SECONDS); } catch (Exception e) { scriptFutureException = e; } if (cause instanceof AssumptionViolatedException) { throw cause; } if (latch.hasException()) { if (cause instanceof InterruptedException) { throw latch.getException(); } throw cause.initCause(latch.getException()); } if (scriptFutureException != null) { if (scriptFutureException instanceof ExecutionException) { throw scriptFutureException.getCause().initCause(cause); } throw cause; } try { assertEquals("Specified behavior did not match", scripts.getExpectedScript(), scripts.getObservedScript()); } catch (ComparisonFailure f) { throw new MultipleFailureException(Arrays.asList(f, cause)); } throw cause; } String k3poSimpleName = K3poRule.class.getSimpleName(); assertTrue(format("Did you instantiate %s with a @Rule and call %s.start() or %s.finish()?", k3poSimpleName, k3poSimpleName, k3poSimpleName), latch.isStartable()); ScriptPair scripts = scriptFuture.get(); assertEquals("Specified behavior did not match", scripts.getExpectedScript(), scripts.getObservedScript()); } finally { try { scriptRunner.dispose(); } finally { scriptFuture.cancel(true); Thread.interrupted(); } } }