Code example for ConnectivityManager: Querying Network Reachability

Methods: getActiveNetworkInfo

0
 
    @Test 
    public void networkInfoShouldReturnTrueCorrectly() { 
        shadowOfActiveNetworkInfo.setConnectionStatus(true);
 
        assertTrue(connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting());
        assertTrue(connectivityManager.getActiveNetworkInfo().isConnected());
    } 
 
    @Test 
    public void getNetworkInfoShouldReturnAssignedValue() throws Exception { 
        NetworkInfo networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTING);
        shadowConnectivityManager.setNetworkInfo(ConnectivityManager.TYPE_WIFI, networkInfo);
        NetworkInfo actual = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        assertThat(actual).isSameAs(networkInfo);
        assertThat(actual.getDetailedState()).isEqualTo(NetworkInfo.DetailedState.CONNECTING);
    } 
 
    @Test 
    public void networkInfoShouldReturnFalseCorrectly() { 
        shadowOfActiveNetworkInfo.setConnectionStatus(false);