Search in sources :

Example 1 with ShadowNetworkInfo

use of org.robolectric.shadows.ShadowNetworkInfo in project prebid-mobile-android by prebid.

the class ResultCodeTest method testNetworkError.

@Test
public void testNetworkError() {
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    ConnectivityManager connectivityManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    ShadowNetworkInfo shadowOfActiveNetworkInfo = shadowOf(connectivityManager.getActiveNetworkInfo());
    shadowOfActiveNetworkInfo.setConnectionStatus(false);
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.NETWORK_ERROR);
}
Also used : ConnectivityManager(android.net.ConnectivityManager) ShadowNetworkInfo(org.robolectric.shadows.ShadowNetworkInfo) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)1 MoPubView (com.mopub.mobileads.MoPubView)1 Test (org.junit.Test)1 ShadowNetworkInfo (org.robolectric.shadows.ShadowNetworkInfo)1