### Question:
MongoDbRegionRepository implements RegionRepository { @Override public Region get(String id) { Page page = getPageByRegionId(id); for(Region region : page.getRegions()) { if(region.getId().equals(id)) { return region; } } return null; }  @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 get(){ String id = "1111L"; Page page = new PageImpl("1234L"); List<Region> regions = Lists.newArrayList(); Region region = new RegionImpl(id); regions.add(region); page.setRegions(regions); expect(template.findOne(new Query(Criteria.where("regions").elemMatch(Criteria.where("_id").is(id))))).andReturn(page); replay(template); Region result = repo.get(id); assertNotNull(result); assertThat(result, is(equalTo(region))); assertThat(result.getId(), equalTo(id)); }
@Test public void get_null(){ Page page = new PageImpl("1234L"); List<Region> regions = Lists.newArrayList(); Region region = new RegionImpl("1111L"); regions.add(region); page.setRegions(regions); expect(template.findOne(new Query(Criteria.where("regions").elemMatch(Criteria.where("_id").is("2222L"))))).andReturn(page); replay(template); Region result = repo.get("2222L"); assertNull(result); }