@Test public void testContains() throws Exception { final String value = "Value"; final byte[] rawValue = bytesOf(value); when(mockValueCrypto.encrypt(rawValue)).thenReturn(CRYPTO.encrypt(rawValue)); whenCryptoEncryptThanReturn(mockValueCrypto, rawValue); assertThat(cryptoPreferences.contains(PREF_KEY), is(false)); assertThat(cryptoPreferences.edit().putString(PREF_KEY, value).commit(), is(true)); assertThat(cryptoPreferences.contains(PREF_KEY), is(true)); verify(mockKeyCrypto, times(3)).encrypt(rawDecryptedKey); verify(mockValueCrypto).encrypt(rawValue); verifyNoMoreInteractions(mockKeyCrypto, mockValueCrypto); }
@Override public boolean contains(@NonNull final String key) { return delegate.contains(helper.encryptKey(key)); }
CryptoSharedPreferences implements SharedPreferences { @Override public boolean contains(@NonNull final String key) { return delegate.contains(helper.encryptKey(key)); } }
CryptoSharedPreferences implements SharedPreferences { @Override public boolean contains(@NonNull final String key) { return delegate.contains(helper.encryptKey(key)); } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); }
CryptoSharedPreferences implements SharedPreferences { @Override public boolean contains(@NonNull final String key) { return delegate.contains(helper.encryptKey(key)); } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); @Override void registerOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override void unregisterOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override Map<String, ?> getAll(); @Override boolean contains(@NonNull final String key); @Override @Nullable String getString(@NonNull final String key, @Nullable final String defValue); @Override @Nullable Set<String> getStringSet(@NonNull final String key, @Nullable final Set<String> defValues); @Override int getInt(@NonNull final String key, final int defValue); @Override long getLong(@NonNull final String key, final long defValue); @Override float getFloat(@NonNull final String key, final float defValue); @Override boolean getBoolean(@NonNull final String key, final boolean defValue); @SuppressLint("CommitPrefEdits") @Override SharedPreferences.Editor edit(); }
CryptoSharedPreferences implements SharedPreferences { @Override public boolean contains(@NonNull final String key) { return delegate.contains(helper.encryptKey(key)); } @SuppressWarnings("WeakerAccess")  CryptoSharedPreferences(final Builder builder); @Override void registerOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override void unregisterOnSharedPreferenceChangeListener(@NonNull final OnSharedPreferenceChangeListener listener); @Override Map<String, ?> getAll(); @Override boolean contains(@NonNull final String key); @Override @Nullable String getString(@NonNull final String key, @Nullable final String defValue); @Override @Nullable Set<String> getStringSet(@NonNull final String key, @Nullable final Set<String> defValues); @Override int getInt(@NonNull final String key, final int defValue); @Override long getLong(@NonNull final String key, final long defValue); @Override float getFloat(@NonNull final String key, final float defValue); @Override boolean getBoolean(@NonNull final String key, final boolean defValue); @SuppressLint("CommitPrefEdits") @Override SharedPreferences.Editor edit();  }