@Test
public void testTrackIdentifier() throws Exception {

    ApplicationInfo applicationInfo = new ApplicationInfo();
    mPackageInfo.applicationInfo = applicationInfo;
    applicationInfo.sourceDir = UUID.randomUUID().toString();
    final byte[] FAKE_APK_DATA = "this is an apk, awesome right?".getBytes();
    final String FAKE_APK_DATA_MD5 = "771BD8971508985852AF8F96170C52FB";
    try {
        FileOutputStream out = new FileOutputStream(applicationInfo.sourceDir);
        out.write(FAKE_APK_DATA);
        out.close();
    } catch (java.io.IOException e) {
        e.printStackTrace();
    }
    DownloadTracker downloadTracker = new DownloadTracker(mTracker);
    downloadTracker.trackNewAppDownload(new TrackMe(), new DownloadTracker.Extra.ApkChecksum(mContext));
    TestHelper.sleep(100); // APK checksum happens off thread
    verify(mTracker).track(mCaptor.capture());
    checkNewAppDownload(mCaptor.getValue());
    Matcher m = REGEX_DOWNLOADTRACK.matcher(mCaptor.getValue().get(QueryParams.DOWNLOAD));
    assertTrue(m.matches());
    assertEquals("package", m.group(1));
    assertEquals(123, Integer.parseInt(m.group(2)));
    assertEquals(FAKE_APK_DATA_MD5, m.group(3));
    assertEquals("http://installer", mCaptor.getValue().get(QueryParams.REFERRER));
    downloadTracker.trackNewAppDownload(new TrackMe(), new DownloadTracker.Extra.None());
    verify(mTracker, times(2)).track(mCaptor.capture());
    checkNewAppDownload(mCaptor.getValue());
    String downloadParams = mCaptor.getValue().get(QueryParams.DOWNLOAD);
    m = REGEX_DOWNLOADTRACK.matcher(downloadParams);
    assertTrue(downloadParams, m.matches());
    assertEquals(3, m.groupCount());
    assertEquals("package", m.group(1));
    assertEquals(123, Integer.parseInt(m.group(2)));
    assertEquals(null, m.group(3));
    assertEquals("http://installer", mCaptor.getValue().get(QueryParams.REFERRER));
    //noinspection ResultOfMethodCallIgnored
    new File(applicationInfo.sourceDir).delete();
}