NetworkManager { public boolean isOnline() { boolean isOnline; try { final NetworkInfo netInfo = getNetworkInfo(); isOnline = netInfo != null && netInfo.isConnected(); } catch (final SecurityException e) { isOnline = true; } return isOnline; } NetworkManager(Context context); static NetworkManager getInstance(Context context); boolean isOnline(); String getConnectedNetworkType(); boolean isDataRoamingEnabled(); int getNetworkIBType();  }
@Test public void isOnlineTest() { when(mNetworkInfo.isConnected()).thenReturn(true); assertTrue(mNetManager.isOnline()); when(mNetworkInfo.isConnected()).thenReturn(false); assertFalse(mNetManager.isOnline()); when(mNetworkInfo.isConnected()).thenThrow(new SecurityException()); assertTrue(mNetManager.isOnline()); }