DoneAnswer implements Answer<S> { @NotNull @Override public Answer<S> whenFailed(@NotNull Consumer<P4CommandRunner.ServerResultException> c) { if (error != null) { c.accept(error); } return this; } private  DoneAnswer(S result, P4CommandRunner.ServerResultException error); static Answer<S> resolve(@Nullable S s); static Answer<S> reject(@NotNull P4CommandRunner.ServerResultException error); @NotNull @Override Answer<S> whenCompleted(@NotNull Consumer<S> c); @NotNull @Override Answer<S> whenFailed(@NotNull Consumer<P4CommandRunner.ServerResultException> c); @NotNull @Override Answer<T> map(@NotNull Function<S, T> fun); @NotNull @Override Answer<T> mapAsync(@NotNull Function<S, Answer<T>> fun); @NotNull @Override Answer<T> futureMap(@NotNull BiConsumer<S, AnswerSink<T>> func); @Override boolean blockingWait(int timeout, TimeUnit unit);  }
@Test void whenFailed() throws InterruptedException { final P4CommandRunner.ServerResultException error = ResultErrorUtil.createInternalException(); final Answer<Object> da = DoneAnswer.reject(error); assertTrue(da.blockingWait(1, TimeUnit.MILLISECONDS)); final AtomicInteger count = new AtomicInteger(0); da.whenCompleted((c) -> fail("Should never have been called")) .whenFailed((t) -> { assertSame(error, t); count.incrementAndGet(); }); assertEquals(1, count.get()); }