### Question:
SharedPreferencesUniqueIdentifierStorage implements UniqueIdentifierStorage { @Override @NonNull public String getUniqueIdentifier() { String uniqueIdentifier = getStoredIdentifier(); if (!StringUtils.isEmpty(uniqueIdentifier)) { return uniqueIdentifier; } return generateNewUniqueIdentifier(); } SharedPreferencesUniqueIdentifierStorage(SharedPreferences sharedPreferences,
                                                    String key); @Override @NonNull String getUniqueIdentifier();  }### Answer:
@Test public void getUniqueIdentifier_withEmptyUniqueIdentifier_generatesOneAndStoresIt() { when(mSharedPreferences.getString(mKey, "")).thenReturn(""); mStorage.getUniqueIdentifier(); verify(mSharedPreferences).getString(mKey, ""); verify(mEditor).putString(eq(mKey), anyString()); verify(mEditor).apply(); }
@Test public void getUniqueIdentifier_retrievesExistingIdentifier_andDoesNotModifySharedPreferences() { when(mSharedPreferences.getString(mKey, "")).thenReturn("uuid"); String id = mStorage.getUniqueIdentifier(); verifyZeroInteractions(mEditor); verify(mSharedPreferences).getString(mKey, ""); assertThat(id, equalTo("uuid")); }