PreferenceManager { public Map<String, String> find(String userId) throws ServerException { requireNonNull(userId, "Required non-null user id"); return preferenceDao.getPreferences(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 shouldGetPreferencesByUser() throws Exception { final Map<String, String> preferences = ImmutableMap.of("name", "value"); when(preferenceDao.getPreferences("user123")).thenReturn(preferences); assertEquals(preferenceManager.find("user123"), preferences); }
@Test public void shouldGetPreferencesByUserAndFilter() throws Exception { final Map<String, String> preferences = ImmutableMap.of("name", "value"); when(preferenceDao.getPreferences("user123", "name.*")).thenReturn(preferences); assertEquals(preferenceManager.find("user123", "name.*"), preferences); }
@Test(expectedExceptions = NullPointerException.class) public void getPreferencesShouldThrowNpeWhenUserIdIsNull() throws Exception { preferenceManager.find(null); }
@Test(expectedExceptions = NullPointerException.class) public void getPreferencesByUserAndFilterShouldThrowNpeWhenUserIdIsNull() throws Exception { preferenceManager.find(null, "name.*"); }