Java 类org.robolectric.shadows.ShadowConnectivityManager 实例源码

项目:JobSchedulerCompat    文件:DeviceTestUtils.java   
public static void setNetworkInfo(Context context, boolean isConnected, boolean isRoaming, boolean isWifi) {
    ShadowConnectivityManager manager =
            shadowOf((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
    NetworkInfo.DetailedState detailedState =
            isConnected ? NetworkInfo.DetailedState.CONNECTED : NetworkInfo.DetailedState.DISCONNECTED;
    int type = isConnected ? (isWifi ? ConnectivityManager.TYPE_WIFI : ConnectivityManager.TYPE_MOBILE) : -1;
    NetworkInfo networkInfo =
            ShadowNetworkInfo.newInstance(detailedState, type, 0, isConnected, isConnected, isRoaming);
    manager.setActiveNetworkInfo(networkInfo);
}
项目:openwebnet-android    文件:UtilityServiceTest.java   
private void toggleNetwork(int networkType, NetworkInfo.DetailedState detailedState) {
    NetworkInfo networkInfo = null;
    switch (detailedState) {
        case CONNECTED:
            networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, networkType, 0, true, true);
            break;
        case DISCONNECTED:
            networkInfo = ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.DISCONNECTED, networkType, 0, true, false);
            break;
    }

    ConnectivityManager cmMock = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE);
    ShadowConnectivityManager shadowConnectivityManager = shadowOf(cmMock);

    shadowConnectivityManager.setNetworkInfo(networkType, networkInfo);
    shadowConnectivityManager.setActiveNetworkInfo(shadowConnectivityManager.getNetworkInfo(networkType));
}
项目:edx-app-android    文件:UiTest.java   
@Before
public void connectToNetwork() {
    ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(
            (ConnectivityManager) RuntimeEnvironment.application
                    .getSystemService(Context.CONNECTIVITY_SERVICE));
    shadowConnectivityManager.setNetworkInfo(ConnectivityManager.TYPE_MOBILE,
            ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED,
                    ConnectivityManager.TYPE_MOBILE, ConnectivityManager.TYPE_MOBILE_MMS,
                    true, false));
    // Set the default network to WiFi, as downloads are always allowed over
    // WiFi regardless of the configuration settings.
    shadowConnectivityManager.setActiveNetworkInfo(
            ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.DISCONNECTED,
                    ConnectivityManager.TYPE_WIFI, 0, true, true));
}
项目:mobile-sdk-android    文件:BannerImpressionTests.java   
@Override
public void setup() {
    super.setup();
    connectivityManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    // Not using Shadows.shadowOf(connectivityManager) because of Robolectric bug when using API23+
    // See: https://github.com/robolectric/robolectric/issues/1862
    shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager);
}
项目:edx-app-android    文件:UiTest.java   
public void disconnectFromNetwork() {
    ShadowConnectivityManager shadowConnectivityManager = Shadows.shadowOf(
            (ConnectivityManager) RuntimeEnvironment.application
                    .getSystemService(Context.CONNECTIVITY_SERVICE));
    shadowConnectivityManager.setActiveNetworkInfo(null);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowConnectivityManager shadowOf(ConnectivityManager instance) {
  return (ShadowConnectivityManager) shadowOf_(instance);
}