### Question:
LostApiClientImpl implements LostApiClient { @Override public void connect() { clientManager.addClient(this); GeofencingApiImpl geofencingApi = getGeofencingImpl(); if (!geofencingApi.isConnected()) { geofencingApi.connect(context); } SettingsApiImpl settingsApi = getSettingsApiImpl(); if (!settingsApi.isConnected()) { settingsApi.connect(context); } FusedLocationProviderApiImpl fusedApi = getFusedLocationProviderApiImpl(); if (fusedApi.isConnected()) { if (connectionCallbacks != null) { connectionCallbacks.onConnected(); fusedApi.addConnectionCallbacks(connectionCallbacks); } } else if (fusedApi.isConnecting()) { if (connectionCallbacks != null) { fusedApi.addConnectionCallbacks(connectionCallbacks); } } else { fusedApi.connect(context, connectionCallbacks); } } LostApiClientImpl(Context context, ConnectionCallbacks callbacks,
      ClientManager clientManager); @Override void connect(); @Override void disconnect(); @Override boolean isConnected(); @Override void registerConnectionCallbacks(ConnectionCallbacks callbacks); @Override void unregisterConnectionCallbacks(ConnectionCallbacks callbacks);  }### Answer:
@Test public void connect_shouldBeConnectedWhenConnectionCallbackInvoked() throws Exception { callbacks.setLostClient(client); client.connect(); assertThat(callbacks.isClientConnectedOnConnect()).isTrue(); }
@Test public void connect_multipleClients_shouldBeConnectedWhenConnectionCallbackInvoked() throws Exception { client.connect(); TestConnectionCallbacks callbacks = new TestConnectionCallbacks(); LostApiClient anotherClient = new LostApiClientImpl(application, callbacks, new LostClientManager(clock, handlerFactory)); callbacks.setLostClient(anotherClient); anotherClient.connect(); assertThat(callbacks.isClientConnectedOnConnect()).isTrue(); }
@Test public void connect_shouldAddConnectionCallbacks() throws Exception { new LostApiClientImpl(application, new LostApiClient.ConnectionCallbacks() { @Override public void onConnected() { new LostApiClientImpl(application, new TestConnectionCallbacks(), new LostClientManager(clock, handlerFactory)).connect(); } @Override public void onConnectionSuspended() { } }, new LostClientManager(clock, handlerFactory)).connect(); FusedLocationProviderApiImpl api = (FusedLocationProviderApiImpl) LocationServices.FusedLocationApi; assertThat(api.getServiceConnectionManager().getConnectionCallbacks()).hasSize(2); }