@Override
    public void prepareTest(Object test) {
      AdFetcherFactory.setInstance(new TestAdFetcherFactory());
      HttpClientFactory.setInstance(new TestHttpClientFactory());
      DateAndTime.setInstance(new TestDateAndTime());
      CustomEventBannerFactory.setInstance(new TestCustomEventBannerFactory());
      CustomEventInterstitialFactory.setInstance(new TestCustomEventInterstitialFactory());
      CustomEventBannerAdapterFactory.setInstance(new TestCustomEventBannerAdapterFactory());
      MraidViewFactory.setInstance(new TestMraidViewFactory());
      MoPubViewFactory.setInstance(new TestMoPubViewFactory());
      CustomEventInterstitialAdapterFactory.setInstance(
          new TestCustomEventInterstitialAdapterFactory());
      HtmlBannerWebViewFactory.setInstance(new TestHtmlBannerWebViewFactory());
      HtmlInterstitialWebViewFactory.setInstance(new TestHtmlInterstitialWebViewFactory());
      AdViewControllerFactory.setInstance(new TestAdViewControllerFactory());
      ViewGestureDetectorFactory.setInstance(new TestViewGestureDetectorFactory());
      VastManagerFactory.setInstance(new TestVastManagerFactory());
      VastVideoDownloadTaskFactory.setInstance(new TestVastVideoDownloadTaskFactory());
      MethodBuilderFactory.setInstance(new TestMethodBuilderFactory());
      CustomEventNativeFactory.setInstance(new TestCustomEventNativeFactory());
      ShadowAsyncTasks.reset();
      MoPubEvents.setEventDispatcher(mock(MoPubEvents.EventDispatcher.class));
      MoPub.setLocationAwareness(LocationAwareness.NORMAL);
      MoPub.setLocationPrecision(6);

      MockitoAnnotations.initMocks(test);

      AsyncTasks.setExecutor(new RobolectricBackgroundExecutorService());
    }
    @Override
    public void prepareTest(Object test) {
      ClientMetadata.clearForTesting();

      DateAndTime.setInstance(new TestDateAndTime());
      CustomEventBannerFactory.setInstance(new TestCustomEventBannerFactory());
      CustomEventInterstitialFactory.setInstance(new TestCustomEventInterstitialFactory());
      CustomEventBannerAdapterFactory.setInstance(new TestCustomEventBannerAdapterFactory());
      MoPubViewFactory.setInstance(new TestMoPubViewFactory());
      CustomEventInterstitialAdapterFactory.setInstance(
          new TestCustomEventInterstitialAdapterFactory());
      HtmlBannerWebViewFactory.setInstance(new TestHtmlBannerWebViewFactory());
      HtmlInterstitialWebViewFactory.setInstance(new TestHtmlInterstitialWebViewFactory());
      AdViewControllerFactory.setInstance(new TestAdViewControllerFactory());
      VastManagerFactory.setInstance(new TestVastManagerFactory());
      MethodBuilderFactory.setInstance(new TestMethodBuilderFactory());
      CustomEventNativeFactory.setInstance(new TestCustomEventNativeFactory());
      MraidControllerFactory.setInstance(new TestMraidControllerFactory());

      ShadowAsyncTasks.reset();
      ShadowMoPubHttpUrlConnection.reset();
      MoPubEvents.setEventDispatcher(mock(EventDispatcher.class));
      MoPub.setLocationAwareness(LocationAwareness.NORMAL);
      MoPub.setLocationPrecision(6);

      MockitoAnnotations.initMocks(test);

      AsyncTasks.setExecutor(new RoboExecutorService());
      CacheService.clearAndNullCaches();
    }
  @Before
  public void setUp() throws Exception {
    moPubView = mock(MoPubView.class);
    stub(moPubView.getAdTimeoutDelay()).toReturn(null);

    subject = new CustomEventBannerAdapter(moPubView, CLASS_NAME, JSON_PARAMS);

    expectedLocalExtras = new HashMap<String, Object>();
    expectedServerExtras = new HashMap<String, String>();

    banner = CustomEventBannerFactory.create(CLASS_NAME);
  }
  public CustomEventBannerAdapter(MoPubView moPubView, String className, String classData) {
    mHandler = new Handler();
    mMoPubView = moPubView;
    mContext = moPubView.getContext();
    mLocalExtras = new HashMap<String, Object>();
    mServerExtras = new HashMap<String, String>();
    mTimeout =
        new Runnable() {
          @Override
          public void run() {
            Log.d("MoPub", "Third-party network timed out.");
            onBannerFailed(NETWORK_TIMEOUT);
            invalidate();
          }
        };

    Log.d("MoPub", "Attempting to invoke custom event: " + className);
    try {
      mCustomEventBanner = CustomEventBannerFactory.create(className);
    } catch (Exception exception) {
      Log.d("MoPub", "Couldn't locate or instantiate custom event: " + className + ".");
      mMoPubView.loadFailUrl(ADAPTER_NOT_FOUND);
      return;
    }

    // Attempt to load the JSON extras into mServerExtras.
    try {
      mServerExtras = Json.jsonStringToMap(classData);
    } catch (Exception exception) {
      Log.d("MoPub", "Failed to create Map from JSON: " + classData + exception.toString());
    }

    mLocalExtras = mMoPubView.getLocalExtras();
    if (mMoPubView.getLocation() != null) {
      mLocalExtras.put("location", mMoPubView.getLocation());
    }
    if (mMoPubView.getAdViewController() != null) {
      mLocalExtras.put(AD_CONFIGURATION_KEY, mMoPubView.getAdViewController().getAdConfiguration());
    }
  }
 public static CustomEventBanner create(String className) throws Exception {
   return instance.internalCreate(className);
 }