Search in sources :

Example 21 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class TransactionTest method testCreativeFactoryListener.

// Tests when creative factories return
@Test
public void testCreativeFactoryListener() throws Exception {
    List<CreativeModel> mockCreativeModels = Collections.singletonList(mock(CreativeModel.class));
    Transaction.Listener mockListener = mock(Transaction.Listener.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(mockCreativeModels, ""), mock(InterstitialManager.class), mockListener);
    Transaction.CreativeFactoryListener creativeFactoryListener = new Transaction.CreativeFactoryListener(transaction);
    // No more Creatives to construct
    // Transaction.Listener.onSuccess is called
    creativeFactoryListener.onSuccess();
    verify(mockListener).onTransactionSuccess(transaction);
    // More Creatives to construct
    // Transaction.Listener.onSuccess is not called
    reset(mockListener);
    Iterator<CreativeFactory> mockIterator = mock(Iterator.class);
    when(mockIterator.hasNext()).thenReturn(true);
    when(mockIterator.next()).thenReturn(mock(CreativeFactory.class));
    WhiteBox.setInternalState(transaction, "mCreativeFactoryIterator", mockIterator);
    creativeFactoryListener.onSuccess();
    verify(mockListener, never()).onTransactionSuccess(transaction);
    // On failure, Transaction.Listener.onFailure should be called
    AdException adException = new AdException("type", "message");
    creativeFactoryListener.onFailure(adException);
    verify(mockListener).onTransactionFailure(eq(adException), anyString());
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 22 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class TransactionTest method testTransactionInit.

@Test
public void testTransactionInit() throws Exception {
    List<CreativeModel> creativeModels = new ArrayList<>();
    CreativeModel mockCreativeModel = mock(CreativeModel.class);
    creativeModels.add(mockCreativeModel);
    Transaction.Listener mockOxTransactionListener = mock(Transaction.Listener.class);
    // Valid
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    assertNotNull(transaction);
    // No context
    boolean hasException = false;
    try {
        Transaction.createTransaction(null, createModelResult(creativeModels, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(null, "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // Empty creative models
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(new ArrayList<>(), "ts"), mockInterstitialManager, mockOxTransactionListener);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
    // No listener
    hasException = false;
    try {
        Transaction.createTransaction(mMockContext, createModelResult(creativeModels, "ts"), mockInterstitialManager, null);
    } catch (AdException e) {
        hasException = true;
    }
    assertTrue(hasException);
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) ArrayList(java.util.ArrayList) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 23 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class MediationBaseAdUnitTest method whenOnErrorReceived_PassErrorMessage.

@Test
public void whenOnErrorReceived_PassErrorMessage() {
    PrebidRenderingSettings.setAccountId("id");
    OnFetchCompleteListener mockListener = mock(OnFetchCompleteListener.class);
    AdException adException = new AdException(AdException.INTERNAL_ERROR, "");
    mBaseAdUnit.fetchDemand(mockListener);
    mBaseAdUnit.onErrorReceived(adException);
    verify(mockListener).onComplete(FetchDemandResult.SERVER_ERROR);
}
Also used : OnFetchCompleteListener(org.prebid.mobile.rendering.bidding.listeners.OnFetchCompleteListener) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 24 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class RewardedAdUnitTest method onFailedAndNoWinnerBid_AdStatusReadyForLoadNotifyErrorListener.

@Test
public void onFailedAndNoWinnerBid_AdStatusReadyForLoadNotifyErrorListener() {
    final AdException exception = new AdException(AdException.INTERNAL_ERROR, "Test");
    final RewardedVideoEventListener eventListener = getEventListener();
    eventListener.onAdFailed(exception);
    verify(mMockRewardedAdUnitListener, times(1)).onAdFailed(mRewardedAdUnit, exception);
    assertEquals(READY_FOR_LOAD, mRewardedAdUnit.getAdUnitState());
}
Also used : RewardedVideoEventListener(org.prebid.mobile.rendering.bidding.listeners.RewardedVideoEventListener) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 25 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class CreativeFactoryTest method testCreativeFactoryCreativeResolutionListener.

@Test
public void testCreativeFactoryCreativeResolutionListener() throws Exception {
    CreativeFactory mockCreativeFactory = mock(CreativeFactory.class);
    CreativeFactory.Listener mockCreativeFactoryListener = mock(CreativeFactory.Listener.class);
    CreativeFactory.CreativeFactoryCreativeResolutionListener creativeResolutionListener = new CreativeFactory.CreativeFactoryCreativeResolutionListener(mockCreativeFactory);
    WhiteBox.field(CreativeFactory.class, "mListener").set(mockCreativeFactory, mockCreativeFactoryListener);
    WhiteBox.field(CreativeFactory.class, "mTimeoutHandler").set(mockCreativeFactory, mock(Handler.class));
    // Success
    creativeResolutionListener.creativeReady(mock(AbstractCreative.class));
    verify(mockCreativeFactoryListener).onSuccess();
    // Failure
    AdException adException = new AdException(AdException.INTERNAL_ERROR, "msg");
    creativeResolutionListener.creativeFailed(adException);
    verify(mockCreativeFactoryListener).onFailure(adException);
}
Also used : AbstractCreative(org.prebid.mobile.rendering.models.AbstractCreative) Handler(android.os.Handler) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Aggregations

AdException (org.prebid.mobile.rendering.errors.AdException)54 Test (org.junit.Test)25 InterstitialController (org.prebid.mobile.rendering.bidding.display.InterstitialController)7 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)6 AdError (com.google.android.gms.ads.AdError)5 BidResponse (org.prebid.mobile.rendering.bidding.data.bid.BidResponse)5 Bid (org.prebid.mobile.rendering.bidding.data.bid.Bid)4 InterstitialControllerListener (org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener)4 CreativeModel (org.prebid.mobile.rendering.models.CreativeModel)4 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)4 Context (android.content.Context)2 Bundle (android.os.Bundle)2 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)2 BannerEventListener (org.prebid.mobile.rendering.bidding.listeners.BannerEventListener)2 InterstitialEventListener (org.prebid.mobile.rendering.bidding.listeners.InterstitialEventListener)2 RewardedVideoEventListener (org.prebid.mobile.rendering.bidding.listeners.RewardedVideoEventListener)2 VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)2