Search in sources :

Example 46 with MoPubView

use of com.mopub.mobileads.MoPubView 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)

Example 47 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class ResultCodeTest method testInvalidContext.

@Test
public void testInvalidContext() throws Exception {
    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setPrebidServerAccountId("123456");
    PrebidMobile.setApplicationContext(null);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus()));
    InterstitialAdUnit adUnit = new InterstitialAdUnit("123456");
    MoPubView testView = new MoPubView(activity);
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testView, mockListener);
    verify(mockListener).onComplete(ResultCode.INVALID_CONTEXT);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HttpUrl(okhttp3.HttpUrl) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 48 with MoPubView

use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.

the class UtilTest method testSupportedAdObject.

@Test
public void testSupportedAdObject() throws Exception {
    MoPubView testView = new MoPubView(activity);
    assertTrue(Util.supportedAdObject(testView));
    assertFalse(Util.supportedAdObject(null));
    MoPubInterstitial interstitial = new MoPubInterstitial(activity, "");
    assertTrue(Util.supportedAdObject(interstitial));
    AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
    assertTrue(Util.supportedAdObject(request));
    AdManagerAdRequest.Builder requestBuilder = new AdManagerAdRequest.Builder();
    assertTrue(Util.supportedAdObject(requestBuilder));
    Object object = new Object();
    assertFalse(Util.supportedAdObject(object));
}
Also used : MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) JSONObject(org.json.JSONObject) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Aggregations

MoPubView (com.mopub.mobileads.MoPubView)48 Test (org.junit.Test)38 FrameLayout (android.widget.FrameLayout)26 BannerAdUnit (org.prebid.mobile.BannerAdUnit)23 OnCompleteListener (org.prebid.mobile.OnCompleteListener)23 ResultCode (org.prebid.mobile.ResultCode)23 MockResponse (okhttp3.mockwebserver.MockResponse)15 HttpUrl (okhttp3.HttpUrl)8 Dispatcher (okhttp3.mockwebserver.Dispatcher)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)7 ShadowLooper (org.robolectric.shadows.ShadowLooper)7 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)5 JSONException (org.json.JSONException)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json.JSONObject)4 AdUnit (org.prebid.mobile.AdUnit)4 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)3