### Question:
MongoDbRegionRepository implements RegionRepository { @Override public Region save(Region item) { Page page; int index; String itemId = item.getId(); if(itemId == null) { page = getPageFromRepository(item); page.getRegions().add(item); index = page.getRegions().size()-1; } else { page = getPageByRegionId(itemId); index = replaceRegion(page, item); } Page parentPage = page.getParentPage(); Page saved; if (parentPage != null) { saved = template.save(parentPage); saved = findSubpageByRegionId(itemId, saved); } else { saved = template.save(page); } return saved.getRegions().get(index); }  @Override Class<? extends Region> getType(); @Override Region get(String  id); @Override Region save(Region item); @Override void delete(Region item); @Override List<Region> getAll(); @Override List<Region> getLimitedList(int offset, int pageSize); @Override int getCountAll(); MongoPageOperations getTemplate(); void setTemplate(MongoPageOperations template);  }### Answer:
@Test public void save(){ Page page = new PageImpl("1234L"); List<Region> regions = Lists.newArrayList(); Region item = new RegionImpl("1111L"); regions.add(item); page.setRegions(regions); expect(template.findOne(new Query(Criteria.where("regions").elemMatch(Criteria.where("_id").is("1111L"))))).andReturn(page); expect(template.save(isA(Page.class))).andReturn(page); replay(template); Region result = repo.save(item); assertThat(result.getId(), is(equalTo("1111L"))); assertThat(result, is(sameInstance(item))); }