### Question:
MongoDbPageConverter implements HydratingModelConverter<Page, MongoDbPage> { @Override public void hydrate(MongoDbPage page) { if (page == null) { return; } page.setPageLayout(pageLayoutRepository.getByPageLayoutCode(page.getPageLayoutCode())); for (PageUser user : page.getMembers()) { user.setPage(page); } for (Region region : page.getRegions()) { region.setPage(page); hydrate(region); } if (page.getSubPages() != null) { for (Page subPage : page.getSubPages()) { subPage.setParentPage(page); if (subPage instanceof MongoDbPage) { hydrate((MongoDbPage) subPage); } } } }  @Override Class<Page> getSourceType(); @Override MongoDbPage convert(Page sourcePage); PageUserImpl convert(PageUser sourceUser); @Override void hydrate(MongoDbPage page); void hydrate(RegionWidgetImpl widget, Region region); RegionWidgetImpl convert(RegionWidget sourceRegionWidget); void setPageLayoutRepository(PageLayoutRepository pageLayoutRepository);  }### Answer:
@Test public void hydratePage_valid() { MongoDbPage page = new MongoDbPage(); page.setRegions(Lists.<Region>newLinkedList()); Region region1 = new RegionImpl(); Region region2 = new RegionImpl(); region1.setRegionWidgets(Lists.<RegionWidget>newLinkedList()); region2.setRegionWidgets(Lists.<RegionWidget>newLinkedList()); RegionWidget rw1 = new RegionWidgetImpl(); region1.getRegionWidgets().add(rw1); RegionWidget rw2 = new RegionWidgetImpl(); region2.getRegionWidgets().add(rw2); page.getRegions().add(region1); page.getRegions().add(region2); page.setMembers(Lists.<PageUser>newLinkedList()); PageUserImpl member1 = new PageUserImpl(); PageUser member2 = new PageUserImpl(); page.getMembers().add(member1); page.getMembers().add(member2); Region subRegion = new RegionImpl(); subRegion.setRegionWidgets(Lists.<RegionWidget>newLinkedList()); RegionWidget subRegionWidget = new RegionWidgetImpl(); subRegion.getRegionWidgets().add(subRegionWidget); page.setSubPages(Lists.<Page>newLinkedList()); MongoDbPage subPage1 = new MongoDbPage(); PageUserImpl subMember = new PageUserImpl(); subPage1.setMembers(Lists.<PageUser>newLinkedList()); subPage1.setRegions(Lists.<Region>newLinkedList()); subPage1.getMembers().add(subMember); subPage1.getRegions().add(subRegion); Page subPage2 = new PageImpl(); subPage2.setMembers(Lists.<PageUser>newLinkedList()); subPage2.setRegions(Lists.<Region>newLinkedList()); page.getSubPages().add(subPage1); page.getSubPages().add(subPage2); PageLayout pageLayout = new PageLayoutImpl(); pageLayout.setCode("asdf"); page.setPageLayoutCode(pageLayout.getCode()); expect(pageLayoutRepository.getByPageLayoutCode(page.getPageLayoutCode())).andReturn(pageLayout); replay(pageLayoutRepository); converter.hydrate(page); assertThat(page.getPageLayout(), is(sameInstance(pageLayout))); assertThat(page.getMembers().get(0), is(instanceOf(PageUserImpl.class))); assertThat((MongoDbPage)region1.getPage(), is(sameInstance(page))); assertThat((MongoDbPage)subPage1.getParentPage(), is(sameInstance(page))); assertThat((MongoDbPage)subPage2.getParentPage(), is(sameInstance(page))); assertThat(page.getRegions().get(0).getRegionWidgets().get(0), is(sameInstance(rw1))); }
@Test public void hydrateWidgetRegion_valid() { RegionWidgetImpl rw = new RegionWidgetImpl(); Region region = new RegionImpl(); converter.hydrate(rw, region); assertThat(rw.getRegion(), is(sameInstance(region))); }
@Test public void hydratePage_null() { MongoDbPage page = null; converter.hydrate(page); assertThat(true, is(true)); }