public void run() { String url = new ConversionUrlGenerator().generateUrlString(TRACK_HOST); Log.d("MoPub", "Conversion track: " + url); DefaultHttpClient httpClient = HttpClientFactory.create(); HttpResponse response; try { HttpGet httpget = new HttpGet(url); response = httpClient.execute(httpget); } catch (Exception e) { Log.d("MoPub", "Conversion track failed [" + e.getClass().getSimpleName() + "]: " + url); return; } if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { Log.d("MoPub", "Conversion track failed: Status code != 200."); return; } HttpEntity entity = response.getEntity(); if (entity == null || entity.getContentLength() == 0) { Log.d("MoPub", "Conversion track failed: Response was empty."); return; } // If we made it here, the request has been tracked Log.d("MoPub", "Conversion track successful."); mSharedPreferences.edit().putBoolean(mIsTrackedKey, true).commit(); }
@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()); }