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());
}
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);
}
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);
}
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());
}
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);
}
Aggregations