code: public static Answer<Void> returnFailure(final Throwable result) {
      return new Answer<Void>() {
        @Override
        public Void answer(InvocationOnMock invocation) {
          for (Object arg : invocation.getArguments()) {
            if (arg instanceof AsyncCallback<?>) {
              ((AsyncCallback<?>) arg).onFailure(result);
              return null;
            }
          }
          throw new IllegalStateException(
              "returnFailure can only be used for methods that take an AsyncCallback as a parameter");
        }
      };
    }
docs: Invokes {@link AsyncCallback#onFailure} on the first argument of type {@link AsyncCallback}
  passed to the method. The method must take an {@link AsyncCallback} parameter of the
  appropriate type. Used like this:
  
  <pre>
  doAnswer(returnFailure(new IOException())).when(myService).getData(any(AsyncCallback.class));
  </pre>
  
  @param result argument to pass to onFailure
  @return an answer that invokes onFailure with the given argument