### Question:
JpaPortalPreferenceRepository implements PortalPreferenceRepository { @Override public PortalPreference getByKey(String key) { final TypedQuery<JpaPortalPreference> query = manager.createNamedQuery(JpaPortalPreference.GET_BY_KEY, JpaPortalPreference.class); query.setParameter(JpaPortalPreference.PARAM_KEY, key); return getSingleResult(query.getResultList()); }  @Override List<PortalPreference> getAll(); @Override List<PortalPreference> getLimitedList(int offset, int pageSize); @Override int getCountAll(); @Override PortalPreference getByKey(String key); @Override Class<? extends PortalPreference> getType(); @Override PortalPreference get(String id); @Override PortalPreference save(PortalPreference item); @Override void delete(PortalPreference item);  }### Answer:
@Test public void testGetByKey() { PortalPreference preference = repository.getByKey("color"); assertNotNull(preference); assertTrue("Expecting preference with one of the values to be red", preference.getValues().contains("red")); assertTrue("Expecting preference with one of the values to be blue", preference.getValues().contains("blue")); }
@Test public void testGetByKey_notExisting() { PortalPreference preference = repository.getByKey("foo"); assertNull(preference); }