### Question:
MongoDbPortalPreferenceRepository implements PortalPreferenceRepository { @Override public PortalPreference getByKey(String key) { return template.findOne(query(where("key").is(key)), CLASS, PREFERENCE_COLLECTION); }  @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); void setTemplate(MongoOperations template); void setConverter(HydratingConverterFactory converter); static final Class<PortalPreferenceImpl> CLASS; }### Answer:
@Test public void getByKey_Valid(){ String key = "key"; PortalPreferenceImpl found = new PortalPreferenceImpl(); expect(template.findOne(query(where("key").is(key)), preferenceRepository.CLASS, CollectionNames.PREFERENCE_COLLECTION)).andReturn(found); replay(template); assertThat(found, is(sameInstance(preferenceRepository.getByKey(key)))); }