@Test public void ApiClient_Connected_Dispose() { RxLocationMaybeOnSubscribe<Object> maybeOnSubscribe = spy(new RxLocationMaybeOnSubscribe<Object>(ctx, new Api[] {}, null) { @Override protected void onGoogleApiClientReady(GoogleApiClient apiClient, MaybeEmitter<? super Object> emitter) { } }); doAnswer(invocation -> { RxLocationBaseOnSubscribe.ApiClientConnectionCallbacks callbacks = invocation.getArgument(0); callbacks.setClient(apiClient); callbacks.onConnected(null); return apiClient; }).when(maybeOnSubscribe).createApiClient(Matchers.any(RxLocationBaseOnSubscribe.ApiClientConnectionCallbacks.class)); doReturn(true).when(apiClient).isConnected(); Maybe.create(maybeOnSubscribe).subscribe().dispose(); verify(maybeOnSubscribe).onUnsubscribed(apiClient); verify(apiClient).disconnect(); }
@Override public final void subscribe(MaybeEmitter<T> emitter) throws Exception { final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter)); try { apiClient.connect(); } catch (Throwable ex) { emitter.onError(ex); } emitter.setCancellable(() -> { if (apiClient.isConnected()) { onUnsubscribed(apiClient); } apiClient.disconnect(); }); }
RxLocationMaybeOnSubscribe extends RxLocationBaseOnSubscribe<T> implements MaybeOnSubscribe<T> { @Override public final void subscribe(MaybeEmitter<T> emitter) throws Exception { final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter)); try { apiClient.connect(); } catch (Throwable ex) { emitter.onError(ex); } emitter.setCancellable(() -> { if (apiClient.isConnected()) { onUnsubscribed(apiClient); } apiClient.disconnect(); }); } }
RxLocationMaybeOnSubscribe extends RxLocationBaseOnSubscribe<T> implements MaybeOnSubscribe<T> { @Override public final void subscribe(MaybeEmitter<T> emitter) throws Exception { final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter)); try { apiClient.connect(); } catch (Throwable ex) { emitter.onError(ex); } emitter.setCancellable(() -> { if (apiClient.isConnected()) { onUnsubscribed(apiClient); } apiClient.disconnect(); }); } protected  RxLocationMaybeOnSubscribe(@NonNull RxLocation rxLocation, Long timeout, TimeUnit timeUnit); protected  RxLocationMaybeOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes); }
RxLocationMaybeOnSubscribe extends RxLocationBaseOnSubscribe<T> implements MaybeOnSubscribe<T> { @Override public final void subscribe(MaybeEmitter<T> emitter) throws Exception { final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter)); try { apiClient.connect(); } catch (Throwable ex) { emitter.onError(ex); } emitter.setCancellable(() -> { if (apiClient.isConnected()) { onUnsubscribed(apiClient); } apiClient.disconnect(); }); } protected  RxLocationMaybeOnSubscribe(@NonNull RxLocation rxLocation, Long timeout, TimeUnit timeUnit); protected  RxLocationMaybeOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes); @Override final void subscribe(MaybeEmitter<T> emitter); }
RxLocationMaybeOnSubscribe extends RxLocationBaseOnSubscribe<T> implements MaybeOnSubscribe<T> { @Override public final void subscribe(MaybeEmitter<T> emitter) throws Exception { final GoogleApiClient apiClient = createApiClient(new ApiClientConnectionCallbacks(emitter)); try { apiClient.connect(); } catch (Throwable ex) { emitter.onError(ex); } emitter.setCancellable(() -> { if (apiClient.isConnected()) { onUnsubscribed(apiClient); } apiClient.disconnect(); }); } protected  RxLocationMaybeOnSubscribe(@NonNull RxLocation rxLocation, Long timeout, TimeUnit timeUnit); protected  RxLocationMaybeOnSubscribe(@NonNull Context ctx, @NonNull Api<? extends Api.ApiOptions.NotRequiredOptions>[] services, Scope[] scopes); @Override final void subscribe(MaybeEmitter<T> emitter);  }