@Test public void givenActiveNetworkInfoIsNotAvailable_WhenConnectivityIsChecked_ThenItResultsToDisconnectedFromInternet() { when(connectivityManagerMock.getActiveNetworkInfo()).thenReturn(null); final boolean isAvailable = internetAvailabilityDetector.isAvailable(); verify(connectivityManagerMock, times(1)).getActiveNetworkInfo(); verifyNoMoreInteractions(connectivityManagerMock); verifyZeroInteractions(activeNetworkInfoMock); assertThat(isAvailable).isFalse(); }
@Override public boolean isAvailable() { @Nullable final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { Timber.v("Internet connection is available; Connected to WiFi."); return true; } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { Timber.v("Internet connection is available; Connected to the mobile provider's data plan."); return true; } else { Timber.v("Internet connection is available. [Network Type: %d]", activeNetworkInfo.getType()); return true; } } else { Timber.d("Internet connection is not available at the moment."); return false; } }
InternetAvailabilityDetector implements AvailabilityDetector { @Override public boolean isAvailable() { @Nullable final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { Timber.v("Internet connection is available; Connected to WiFi."); return true; } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { Timber.v("Internet connection is available; Connected to the mobile provider's data plan."); return true; } else { Timber.v("Internet connection is available. [Network Type: %d]", activeNetworkInfo.getType()); return true; } } else { Timber.d("Internet connection is not available at the moment."); return false; } } }
InternetAvailabilityDetector implements AvailabilityDetector { @Override public boolean isAvailable() { @Nullable final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { Timber.v("Internet connection is available; Connected to WiFi."); return true; } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { Timber.v("Internet connection is available; Connected to the mobile provider's data plan."); return true; } else { Timber.v("Internet connection is available. [Network Type: %d]", activeNetworkInfo.getType()); return true; } } else { Timber.d("Internet connection is not available at the moment."); return false; } } InternetAvailabilityDetector(final PostsApplication application); }
InternetAvailabilityDetector implements AvailabilityDetector { @Override public boolean isAvailable() { @Nullable final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { Timber.v("Internet connection is available; Connected to WiFi."); return true; } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { Timber.v("Internet connection is available; Connected to the mobile provider's data plan."); return true; } else { Timber.v("Internet connection is available. [Network Type: %d]", activeNetworkInfo.getType()); return true; } } else { Timber.d("Internet connection is not available at the moment."); return false; } } InternetAvailabilityDetector(final PostsApplication application); @Override boolean isAvailable(); }
InternetAvailabilityDetector implements AvailabilityDetector { @Override public boolean isAvailable() { @Nullable final NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetworkInfo != null) { if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { Timber.v("Internet connection is available; Connected to WiFi."); return true; } else if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { Timber.v("Internet connection is available; Connected to the mobile provider's data plan."); return true; } else { Timber.v("Internet connection is available. [Network Type: %d]", activeNetworkInfo.getType()); return true; } } else { Timber.d("Internet connection is not available at the moment."); return false; } } InternetAvailabilityDetector(final PostsApplication application); @Override boolean isAvailable();  }