### Question:
DefaultRxHttpClient implements RxHttpClient { @Override public <T> Maybe<T> prepare(Request request, Supplier<? extends AsyncHandler<T>> handlerSupplier) { requireNonNull(request); requireNonNull(handlerSupplier); return Maybe.create(emitter -> { final AsyncHandler<?> bridge = createBridge(emitter, handlerSupplier.get()); final Future<?> responseFuture = asyncHttpClient.executeRequest(request, bridge); emitter.setDisposable(Disposables.fromFuture(responseFuture)); }); } DefaultRxHttpClient(AsyncHttpClient asyncHttpClient); @Override Maybe<T> prepare(Request request, Supplier<? extends AsyncHandler<T>> handlerSupplier);  }### Answer:
@Test(expectedExceptions = NullPointerException.class) public void rejectsNullHandlerSupplier() { underTest.prepare(request, null); }
@Test public void emitsNullPointerExceptionWhenNullHandlerIsSupplied() { given(handlerSupplier.get()).willReturn(null); final TestObserver<Object> subscriber = new TestObserver<>(); underTest.prepare(request, handlerSupplier).subscribe(subscriber); subscriber.assertTerminated(); subscriber.assertNoValues(); subscriber.assertError(NullPointerException.class); then(handlerSupplier).should().get(); verifyNoMoreInteractions(handlerSupplier); }
@Test public void usesVanillaAsyncHandler() { given(handlerSupplier.get()).willReturn(handler); underTest.prepare(request, handlerSupplier).subscribe(); then(asyncHttpClient).should().executeRequest(eq(request), handlerCaptor.capture()); final AsyncHandler<Object> bridge = handlerCaptor.getValue(); assertThat(bridge, is(not(instanceOf(ProgressAsyncHandler.class)))); }
@Test public void usesProgressAsyncHandler() { given(handlerSupplier.get()).willReturn(progressHandler); underTest.prepare(request, handlerSupplier).subscribe(); then(asyncHttpClient).should().executeRequest(eq(request), handlerCaptor.capture()); final AsyncHandler<Object> bridge = handlerCaptor.getValue(); assertThat(bridge, is(instanceOf(ProgressAsyncHandler.class))); }
@Test public void callsSupplierForEachSubscription() { given(handlerSupplier.get()).willReturn(handler); final Maybe<Object> prepared = underTest.prepare(request, handlerSupplier); prepared.subscribe(); prepared.subscribe(); then(handlerSupplier).should(times(2)).get(); }
@Test public void cancelsResponseFutureOnDispose() throws Exception { given(handlerSupplier.get()).willReturn(handler); given(asyncHttpClient.executeRequest(eq(request), any())).willReturn(resposeFuture); underTest.prepare(request, handlerSupplier).subscribe().dispose(); then(asyncHttpClient).should().executeRequest(eq(request), handlerCaptor.capture()); final AsyncHandler<Object> bridge = handlerCaptor.getValue(); then(resposeFuture).should().cancel(true); verifyZeroInteractions(handler); assertThat(bridge.onStatusReceived(null), is(AsyncHandler.State.ABORT)); verify(handler).onThrowable(isA(DisposedException.class)); verifyNoMoreInteractions(handler); }
@Test(expectedExceptions = NullPointerException.class) public void rejectsNullRequest() { underTest.prepare(null, handlerSupplier); }