DownloadTracker { public void trackOnce(TrackMe baseTrackme, @NonNull Extra extra) { String firedKey = "downloaded:" + mPkgInfo.packageName + ":" + getVersion(); synchronized (mTrackOnceLock) { if (!mPreferences.getBoolean(firedKey, false)) { mPreferences.edit().putBoolean(firedKey, true).apply(); trackNewAppDownload(baseTrackme, extra); } } } DownloadTracker(Tracker tracker);  DownloadTracker(Tracker tracker, @NonNull PackageInfo packageInfo); void setVersion(@Nullable String version); String getVersion(); void trackOnce(TrackMe baseTrackme, @NonNull Extra extra); void trackNewAppDownload(final TrackMe baseTrackme, @NonNull final Extra extra);  }
@Test public void testTrackAppDownload() throws Exception { DownloadTracker downloadTracker = new DownloadTracker(mTracker); downloadTracker.trackOnce(new TrackMe(), new DownloadTracker.Extra.None()); verify(mTracker).track(mCaptor.capture()); checkNewAppDownload(mCaptor.getValue()); downloadTracker.trackOnce(new TrackMe(), new DownloadTracker.Extra.None()); verify(mTracker, times(1)).track(mCaptor.capture()); }