PreLollipopNetworkObservingStrategy implements NetworkObservingStrategy { protected void tryToUnregisterReceiver(final Context context, final BroadcastReceiver receiver) { try { context.unregisterReceiver(receiver); } catch (Exception exception) { onError("receiver was already unregistered", exception); } }  @Override Observable<Connectivity> observeNetworkConnectivity(final Context context); @Override void onError(final String message, final Exception exception);  }
@Test public void shouldTryToUnregisterReceiver() { final PreLollipopNetworkObservingStrategy strategy = new PreLollipopNetworkObservingStrategy(); final Application context = spy(RuntimeEnvironment.application); strategy.tryToUnregisterReceiver(context, broadcastReceiver); verify(context).unregisterReceiver(broadcastReceiver); }