CollapsedRequestSubject implements CollapsedRequest<T, R> { @Override public void setException(Exception e) { if (!isTerminated()) { subject.onError(e); } else { throw new IllegalStateException("Response has already terminated so exception can not be set", e); } } CollapsedRequestSubject(final R arg, final RequestBatch<?, T, R> containingBatch);  CollapsedRequestSubject(final R arg); @Override R getArgument(); @Override void setResponse(T response); @Override void emitResponse(T response); @Override void setComplete(); void setExceptionIfResponseNotReceived(Exception e); Exception setExceptionIfResponseNotReceived(Exception e, String exceptionMessage); @Override void setException(Exception e); Observable<T> toObservable();  }
@Test public void testSetException() throws InterruptedException, ExecutionException { CollapsedRequestSubject<String, String> cr = new CollapsedRequestSubject<String, String>("hello"); Observable<String> o = cr.toObservable(); Future<String> v = o.toBlocking().toFuture(); cr.setException(new RuntimeException("anException")); try { v.get(); fail("expected exception"); } catch (ExecutionException e) { assertEquals("anException", e.getCause().getMessage()); } }