PreferenceManager { public void remove(String userId) throws ServerException { requireNonNull(userId, "Required non-null user id"); preferenceDao.remove(userId); }  void save(String userId, Map<String, String> preferences); Map<String, String> update(String userId, Map<String, String> preferences); Map<String, String> find(String userId); Map<String, String> find(String userId, String keyFilter); void remove(String userId); void remove(String userId, List<String> names);  }
@Test public void shouldRemoveSpecifiedPreferences() throws Exception { final Map<String, String> existingPreferences = new HashMap<>(); existingPreferences.put("pKey1", "pValue1"); existingPreferences.put("pKey2", "pValue2"); existingPreferences.put("pKey3", "pValue3"); existingPreferences.put("pKey4", "pValue4"); when(preferenceDao.getPreferences(any())).thenReturn(existingPreferences); preferenceManager.remove("user123", asList("pKey1", "pKey5", "odd-pref-name")); verify(preferenceDao).setPreferences(anyString(), preferencesCaptor.capture()); assertEquals( preferencesCaptor.getValue(), ImmutableMap.of( "pKey2", "pValue2", "pKey3", "pValue3", "pKey4", "pValue4")); }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowNpeWhenRemovingPreferencesAndUserIdIsNull() throws Exception { preferenceManager.remove(null); }
@Test public void shouldRemoveUserPreferences() throws Exception { preferenceManager.remove("user123"); verify(preferenceDao).remove("user123"); }