@Test
public void testReceiveGooglePlay() throws Exception {

    InstallReferrerReceiver receiver = new InstallReferrerReceiver();
    Intent testIntent = new Intent("com.android.vending.INSTALL_REFERRER");
    testIntent.setPackage(Robolectric.application.getPackageName());
    String testReferrerData1 = "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name";
    testIntent.putExtra(InstallReferrerReceiver.ARG_KEY_GPLAY_REFERRER, testReferrerData1);
    receiver.onReceive(Robolectric.application.getApplicationContext(), testIntent);
    Thread.sleep(250);
    String referrerDataFromPreferences = getMatomo().getPreferences().getString(InstallReferrerReceiver.PREF_KEY_INSTALL_REFERRER_EXTRAS, null);
    assertEquals(testReferrerData1, referrerDataFromPreferences);
    assertTrue(testIntent.getBooleanExtra("forwarded", false));
    String testReferrerData2 = "pk_campaign=Email-Nov2011&pk_kwd=OrderNow";
    testIntent.putExtra(InstallReferrerReceiver.ARG_KEY_GPLAY_REFERRER, testReferrerData2);
    receiver.onReceive(Robolectric.application.getApplicationContext(), testIntent);
    Thread.sleep(250);
    referrerDataFromPreferences = getMatomo().getPreferences().getString(InstallReferrerReceiver.PREF_KEY_INSTALL_REFERRER_EXTRAS, null);
    assertEquals(testReferrerData1, referrerDataFromPreferences);
    testIntent.putExtra("forwarded", false);
    receiver.onReceive(Robolectric.application.getApplicationContext(), testIntent);
    Thread.sleep(250);
    referrerDataFromPreferences = getMatomo().getPreferences().getString(InstallReferrerReceiver.PREF_KEY_INSTALL_REFERRER_EXTRAS, null);
    assertEquals(testReferrerData2, referrerDataFromPreferences);
}