AdLoader { @Nullable static AdLoader fromAdResponse(AdResponse response, AdViewController adViewController) { MoPubLog.i("Performing custom event."); String adTypeCustomEventName = response.getCustomEventClassName(); if (adTypeCustomEventName != null) { Map<String, String> customEventData = response.getServerExtras(); return new CustomEventAdLoader(adViewController, adTypeCustomEventName, customEventData); } MoPubLog.i("Failed to create custom event."); return null; } AdLoader(AdViewController adViewController);   }
@Test public void fromAdResponse_whenCustomEvent_shouldCreateAdLoadTask() throws Exception { adResponse = adResponse.toBuilder() .setAdType("custom") .setCustomEventClassName("custom event name") .setServerExtras(serverExtras) .build(); AdLoader.CustomEventAdLoader customEventTask = (AdLoader.CustomEventAdLoader) AdLoader.fromAdResponse(adResponse, adViewController); assertThat(customEventTask).isNotNull(); assertThat(customEventTask.getServerExtras()).isEqualTo(serverExtras); }
@Test public void fromAdResponse_whenHtml_shouldBeModernAdLoadTask() { adResponse = adResponse.toBuilder() .setAdType("html") .setCustomEventClassName("com.mopub.mobileads.HtmlBanner") .setServerExtras(serverExtras) .build(); AdLoader.CustomEventAdLoader customEventTask = (AdLoader.CustomEventAdLoader) AdLoader.fromAdResponse(adResponse, adViewController); assertThat(customEventTask).isNotNull(); assertThat(customEventTask.getServerExtras()).has(new Condition<Map<String, String>>() { @Override public boolean matches(final Map<String, String> stringStringMap) { return stringStringMap.containsKey("test"); } }); }
@Test public void fromAdResponse_whenCustomMethod_shouldReturnNull() { adResponse = adResponse.toBuilder() .setCustomEventClassName(null) .build(); assertThat(AdLoader.fromAdResponse(adResponse, adViewController)).isNull(); }