String id = "123";
widget.setId(id);
replaced.setId(id);
replaced.setCollapsed(true);
Page parent = new PageImpl();
Region region = new RegionImpl();
List<Region> regions = new ArrayList<Region>();
regions.add(region);
List<RegionWidget> regionWidgets = new ArrayList<RegionWidget>();
regionWidgets.add(replaced);
parent.setRegions(regions);
region.setRegionWidgets(regionWidgets);
expect(template.findOne(getQuery(id))).andReturn(parent);
expect(template.save(parent)).andReturn(parent);
replay(template);
RegionWidget savedWidget = widgetRepository.save(widget);
assertTrue(region.getRegionWidgets().contains(widget));
assertFalse(region.getRegionWidgets().contains(replaced));
assertThat(savedWidget, is(sameInstance((RegionWidget)widget)));
}