LollipopNetworkObservingStrategy extends Api21BaseNetworkObservingStrategy { @Override public Observable<RxNetworkInfo> observe() { return Observable.create(new LollipopOnSubscribe()).distinctUntilChanged(); } LollipopNetworkObservingStrategy(@NonNull Context context);  LollipopNetworkObservingStrategy(@NonNull Context context,
      @NonNull NetworkRequest networkRequest); @Override Observable<RxNetworkInfo> observe();  }
@Test() public void shouldRegisterWithDefaultNetworkRequest() { NetworkRequest defaultRequest = new NetworkRequest.Builder().build(); ConnectivityManager manager = setUpManagerWithNetworkRequest(null); sut.observe().subscribeWith(testObserver).assertSubscribed(); verify(manager).registerNetworkCallback(eq(defaultRequest), any(NetworkCallback.class)); }
@Test() public void shouldRegisterWithCustomNetworkRequest() { NetworkRequest customRequest = new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI).build(); ConnectivityManager manager = setUpManagerWithNetworkRequest(customRequest); sut.observe().subscribeWith(testObserver).assertSubscribed(); verify(manager).registerNetworkCallback(eq(customRequest), any(NetworkCallback.class)); }
@Test public void shouldSubscribeCorrectly() { sut.observe().subscribeWith(testObserver); testObserver.assertSubscribed().assertValueCount(1); }