ReactiveNetwork { @RequiresPermission(Manifest.permission.INTERNET) public static Observable<Boolean> observeInternetConnectivity() { InternetObservingSettings settings = InternetObservingSettings.create(); return observeInternetConnectivity(settings.strategy(), settings.initialInterval(), settings.interval(), settings.host(), settings.port(), settings.timeout(), settings.httpResponse(), settings.errorHandler()); } 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 observeInternetConnectivityDefaultShouldNotBeNull() { Observable<Boolean> observable; observable = ReactiveNetwork.observeInternetConnectivity(); assertThat(observable).isNotNull(); }
@Test(expected = IllegalArgumentException.class) public void observeInternetConnectivityShouldThrowAnExceptionWhenStrategyIsNull() { final InternetObservingStrategy strategy = null; final ErrorHandler errorHandler = new DefaultErrorHandler(); ReactiveNetwork.observeInternetConnectivity(strategy, TEST_VALID_INITIAL_INTERVAL, TEST_VALID_INTERVAL, TEST_VALID_HOST, TEST_VALID_PORT, TEST_VALID_TIMEOUT, TEST_VALID_HTTP_RESPONSE, errorHandler); }
@Test public void observeInternetConnectivityShouldNotThrowAnExceptionWhenStrategyIsNotNull() { final InternetObservingStrategy strategy = new SocketInternetObservingStrategy(); final ErrorHandler errorHandler = new DefaultErrorHandler(); final Observable<Boolean> observable = ReactiveNetwork.observeInternetConnectivity(strategy, TEST_VALID_INITIAL_INTERVAL, TEST_VALID_INTERVAL, TEST_VALID_HOST, TEST_VALID_PORT, TEST_VALID_TIMEOUT, TEST_VALID_HTTP_RESPONSE, errorHandler); assertThat(observable).isNotNull(); }
@Test public void shouldObserveInternetConnectivityWithCustomSettings() { final int initialInterval = 1; final int interval = 2; final String host = "www.test.com"; int port = 90; int timeout = 3; ErrorHandler testErrorHandler = createTestErrorHandler(); InternetObservingStrategy strategy = createTestInternetObservingStrategy(); InternetObservingSettings settings = InternetObservingSettings.builder() .initialInterval(initialInterval) .interval(interval) .host(host) .port(port) .timeout(timeout) .errorHandler(testErrorHandler) .strategy(strategy) .build(); Observable<Boolean> observable = ReactiveNetwork.observeInternetConnectivity(settings); assertThat(observable).isNotNull(); }