LoginServiceImpl extends BaseRetrofitService<LoginRepository> implements org.unicef.rapidreg.service
        .LoginService { @Override public boolean isOnline() { NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected(); } LoginServiceImpl(ConnectivityManager connectivityManager,
                            TelephonyManager telephonyManager,
                            UserDao userDao); @Override boolean isOnline(); @Override void loginOnline(final String username,
                            final String password,
                            final String url,
                            String imei,
                            final LoginCallback callback); @Override void loginOffline(String username, String password, String url, LoginCallback callback); @Override void destroy(); @Override String loadLastLoginServerUrl(); @Override boolean isUsernameValid(String username); @Override boolean isPasswordValid(String password); @Override boolean isUrlValid(String url);  }
@Test public void should_return_is_not_online_when_network_is_null() throws Exception { when(connectivityManager.getActiveNetworkInfo()).thenReturn(null); assertThat("Should return false", loginService.isOnline(), is(false)); }
@Test public void should_return_is_not_online_when_network_is_not_available() throws Exception { NetworkInfo networkInfo = mock(NetworkInfo.class); when(networkInfo.isAvailable()).thenReturn(false); when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); assertThat("Should return false", loginService.isOnline(), is(false)); }
@Test public void should_return_is_not_online_when_network_is_not_connected() throws Exception { NetworkInfo networkInfo = mock(NetworkInfo.class); when(networkInfo.isConnected()).thenReturn(false); when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); assertThat("Should return false", loginService.isOnline(), is(false)); }
@Test public void should_return_is_online_when_network_is_ok() throws Exception { NetworkInfo networkInfo = mock(NetworkInfo.class); when(networkInfo.isAvailable()).thenReturn(true); when(networkInfo.isConnected()).thenReturn(true); when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); assertThat("Should return true", loginService.isOnline(), is(true)); }