### Question:
MongoDbTagRepository implements TagRepository { @Override public Tag save(Tag item) { return template.count(query(where("keyword").is(item.getKeyword()))) == 0 ? template.save(item) : item; }  @Override List<Tag> getAll(); @Override List<Tag> getLimitedList(int offset, int pageSize); @Override int getCountAll(); @Override Tag getByKeyword(String keyword); @Override Class<? extends Tag> getType(); @Override Tag get(String id); @Override Tag save(Tag item); @Override void delete(Tag item); void setWidgetTemplate(MongoTagOperations tagTemplate);  }### Answer:
@Test public void save(){ String keyword = "KEYWORD"; Tag tag = new TagImpl("ID", keyword); expect(tagTemplate.count(Query.query(Criteria.where("keyword").is(keyword)))).andReturn(0L); expect(tagTemplate.save(tag)).andReturn(tag); replay(tagTemplate); Tag returned = repo.save(tag); verify(tagTemplate); assertThat(returned, is(sameInstance(tag))); }
@Test public void save_more(){ String keyword = "KEYWORD"; Tag tag = new TagImpl("ID", keyword); expect(tagTemplate.count(Query.query(Criteria.where("keyword").is(keyword)))).andReturn(1L); replay(tagTemplate); Tag returned = repo.save(tag); verify(tagTemplate); assertThat(returned, is(sameInstance(tag))); }