### Question:
DefaultPortalPreferenceService implements PortalPreferenceService { @Override public PortalPreference getPreference(String key) { return repository.getByKey(key); } @Autowired  DefaultPortalPreferenceService(PortalPreferenceRepository repository, RaveEventManager manager); @Override Map<String, PortalPreference> getPreferencesAsMap(); @Override PortalPreference getPreference(String key); @Override SearchResult<PortalPreference> getAll(); @Override SearchResult<PortalPreference> getLimitedList(int offset, int pageSize); @Override @Transactional void savePreference(String key, String value); @Override @Transactional void savePreference(String key, List<String> values); @Override @Transactional void savePreference(PortalPreference preference);  }### Answer:
@Test public void testGetPreference() { final String key = "title"; expect(repository.getByKey(key)).andReturn(titlePreference()); replay(repository); final PortalPreference preference = service.getPreference(key); verify(repository); assertEquals("Rave", preference.getValue()); }
@Test public void testGetPreference_notExisting() { final String key = "foo"; expect(repository.getByKey(key)).andReturn(null); replay(repository); final PortalPreference preference = service.getPreference(key); verify(repository); assertNull(preference); }