SharedPreferencesInstallIDProvider implements InstallIDProvider { @Override public String getInstallID() { if (sharedPreferences.contains(preferencesKey)) { return sharedPreferences.getString(preferencesKey, null); } else { return generateAndStoreInstallID(); } } SharedPreferencesInstallIDProvider(SharedPreferences sharedPreferences, String preferencesKey); @Override String getInstallID();  }
@Test public void returnsSameValueEveryTime() { String firstValue = provider.getInstallID(); String secondValue = provider.getInstallID(); assertThat(firstValue, equalTo(secondValue)); }
@Test public void returnsValueWithPrefix() { assertThat(provider.getInstallID(), startsWith("collect:")); }
@Test public void returns24CharacterValue() { assertThat(provider.getInstallID().length(), equalTo(24)); }
@Test public void clearingSharedPreferences_resetsInstallID() { String firstValue = provider.getInstallID(); sharedPreferences.edit().clear().commit(); String secondValue = provider.getInstallID(); assertThat(secondValue, notNullValue()); assertThat(firstValue, not(equalTo(secondValue))); }