MarshmallowNetworkObservingStrategy extends Api21BaseNetworkObservingStrategy { @Override public Observable<RxNetworkInfo> observe() { Observable.create(new MarshmallowOnSubscribe()).subscribeWith(networkChange); return networkChange.distinctUntilChanged().doOnDispose(new OnDisposeAction()); } MarshmallowNetworkObservingStrategy(@NonNull Context context);  MarshmallowNetworkObservingStrategy(@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().assertEmpty(); }
@Test public void shouldGetValue_whenIdleModeChanged_andDeviceNotIdled() { setUpDeviceIdleMode(false); sut.observe().subscribeWith(testObserver); testObserver.assertSubscribed().assertEmpty(); RuntimeEnvironment.application.sendBroadcast(new Intent(ACTION_DEVICE_IDLE_MODE_CHANGED)); testObserver.assertSubscribed().assertValueCount(1); }
@Test public void shouldGetValue_whenIdleModeChanged_andDeviceIdled() { setUpDeviceIdleMode(true); doReturn(false).when(powerManager).isIgnoringBatteryOptimizations(anyString()); sut.observe().subscribeWith(testObserver); testObserver.assertSubscribed().assertEmpty(); RuntimeEnvironment.application.sendBroadcast(new Intent(ACTION_DEVICE_IDLE_MODE_CHANGED)); testObserver.assertSubscribed().assertValue(defaultRxNetworkInfo); }