MoPubConversionTracker { public void reportAppOpen(Context context) { if (context == null) { return; } mContext = context; mPackageName = mContext.getPackageName(); mIsTrackedKey = mPackageName + " tracked"; mSharedPreferences = SharedPreferencesHelper.getSharedPreferences(mContext); if (!isAlreadyTracked()) { GpsHelper.fetchAdvertisingInfoAsync(mContext, new GpsHelperListener() { @Override public void onFetchAdInfoCompleted() { new Thread(new TrackOpen()).start(); } }); } else { MoPubLog.d("Conversion already tracked"); } }  void reportAppOpen(Context context);  }
@Test public void reportAppOpen_onValidHttpResponse_isIdempotent() throws Exception { fakeHttpLayer.addPendingHttpResponse(200, "doesn't matter what this is as long as it's not nothing"); subject.reportAppOpen(context); assertRequestMade(true); fakeHttpLayer.addPendingHttpResponse(200, "doesn't matter what this is as long as it's not nothing"); subject.reportAppOpen(context); assertRequestMade(false); }
@Test public void reportAppOpen_onInvalidStatusCode_shouldMakeSecondRequest() throws Exception { fakeHttpLayer.addPendingHttpResponse(404, "doesn't matter what this is as long as it's not nothing"); subject.reportAppOpen(context); assertRequestMade(true); fakeHttpLayer.addPendingHttpResponse(404, "doesn't matter what this is as long as it's not nothing"); subject.reportAppOpen(context); assertRequestMade(true); }
@Test public void reportAppOpen_onEmptyResponse_shouldMakeSecondRequest() throws Exception { fakeHttpLayer.addPendingHttpResponse(200, ""); subject.reportAppOpen(context); assertRequestMade(true); fakeHttpLayer.addPendingHttpResponse(200, ""); subject.reportAppOpen(context); assertRequestMade(true); }
@Test public void reportAppOpen_whenGooglePlayServicesIsLinkedAndAdInfoIsNotCached_shouldUseAdInfoParams() throws Exception { GpsHelper.setClassNamesForTesting(); GpsHelperTest.verifyCleanClientMetadata(context); GpsHelperTest.TestAdInfo adInfo = new GpsHelperTest.TestAdInfo(); when(methodBuilder.setStatic(any(Class.class))).thenReturn(methodBuilder); when(methodBuilder.addParam(any(Class.class), any())).thenReturn(methodBuilder); when(methodBuilder.execute()).thenReturn( GpsHelper.GOOGLE_PLAY_SUCCESS_CODE, adInfo, adInfo.mAdId, adInfo.mLimitAdTrackingEnabled, GpsHelper.GOOGLE_PLAY_SUCCESS_CODE ); expectedUdid = "ifa%3A" + adInfo.mAdId; dnt = true; fakeHttpLayer.addPendingHttpResponse(200, "doesn't matter what this is as long as it's not nothing"); subject.reportAppOpen(context); Thread.sleep(500); assertRequestMade(true); }