ReactiveNetwork { @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) public static Observable<Connectivity> observeNetworkConnectivity(final Context context) { final NetworkObservingStrategy strategy; if (Preconditions.isAtLeastAndroidMarshmallow()) { strategy = new MarshmallowNetworkObservingStrategy(); } else if (Preconditions.isAtLeastAndroidLollipop()) { strategy = new LollipopNetworkObservingStrategy(); } else { strategy = new PreLollipopNetworkObservingStrategy(); } return observeNetworkConnectivity(context, strategy); } protected  ReactiveNetwork(); static ReactiveNetwork create(); @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) static Observable<Connectivity> observeNetworkConnectivity(final Context context); @RequiresPermission(Manifest.permission.ACCESS_NETWORK_STATE) static Observable<Connectivity> observeNetworkConnectivity(final Context context,
      final NetworkObservingStrategy strategy); @RequiresPermission(Manifest.permission.INTERNET) static Observable<Boolean> observeInternetConnectivity(); @RequiresPermission(Manifest.permission.INTERNET) static Observable<Boolean> observeInternetConnectivity(
      InternetObservingSettings settings); @RequiresPermission(Manifest.permission.INTERNET) static Single<Boolean> checkInternetConnectivity(); @RequiresPermission(Manifest.permission.INTERNET) static Single<Boolean> checkInternetConnectivity(InternetObservingSettings settings); final static String LOG_TAG; }
@Test public void observeNetworkConnectivityWithStrategyShouldNotBeNull() { final Context context = RuntimeEnvironment.application; NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy(); Observable<Connectivity> observable; observable = ReactiveNetwork.observeNetworkConnectivity(context, strategy); assertThat(observable).isNotNull(); }
@Test public void observeNetworkConnectivityShouldBeConnectedOnStartWhenNetworkIsAvailable() { final Application context = RuntimeEnvironment.application; Connectivity connectivity = ReactiveNetwork.observeNetworkConnectivity(context).blockingFirst(); assertThat(connectivity.state()).isEqualTo(NetworkInfo.State.CONNECTED); }
@Test(expected = IllegalArgumentException.class) public void observeNetworkConnectivityShouldThrowAnExceptionForNullContext() { final Context context = null; final NetworkObservingStrategy strategy = new LollipopNetworkObservingStrategy(); ReactiveNetwork.observeNetworkConnectivity(context, strategy); }
@Test(expected = IllegalArgumentException.class) public void observeNetworkConnectivityShouldThrowAnExceptionForNullStrategy() { final Context context = RuntimeEnvironment.application; final NetworkObservingStrategy strategy = null; ReactiveNetwork.observeNetworkConnectivity(context, strategy); }