AbstractMapSelectionActivity extends ListActivity { protected boolean isNetworkAvailable() { final ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netInfo = manager.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnected(); }  abstract Intent getIntentWithMapName(final String mapName);  }
@Test public void testIsNetWorkAvailableReturnsFalseWhenNoNetworkIsAvailable() { final AbstractMapSelectionActivity activitySpy = spy(activity); final ConnectivityManager manager = mock(ConnectivityManager.class); final NetworkInfo networkInfo = mock(NetworkInfo.class); when(activitySpy.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(manager); when(manager.getActiveNetworkInfo()).thenReturn(networkInfo); when(networkInfo.isConnected()).thenReturn(false); assertFalse(activitySpy.isNetworkAvailable()); }
@Test public void testIsNetWorkAvailableReturnsFalseWhenNetworkInfoIsNull() { final AbstractMapSelectionActivity activitySpy = spy(activity); final ConnectivityManager manager = mock(ConnectivityManager.class); final NetworkInfo networkInfo = null; when(activitySpy.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(manager); when(manager.getActiveNetworkInfo()).thenReturn(networkInfo); assertFalse(activitySpy.isNetworkAvailable()); }