Page value = new PageImpl();
value.setRegions(new ArrayList<Region>());
value.getRegions().add(originalRegion);
value.getRegions().add(targetRegion);
Widget widget = new WidgetImpl();
expect(pageRepository.get(PAGE_ID)).andReturn(value);
expect(widgetRepository.get(WIDGET_ID)).andReturn(widget);
expect(regionRepository.save(originalRegion)).andReturn(originalRegion);
replay(pageRepository);
replay(regionRepository);
replay(widgetRepository);
RegionWidget instance = pageService.addWidgetToPage(PAGE_ID, WIDGET_ID);
verify(pageRepository);
verify(regionRepository);
verify(widgetRepository);
verifyPositions(0, instance, true);
assertThat(originalRegion.getRegionWidgets().get(0), is(sameInstance(instance)));
assertThat(instance.getWidgetId(), is(equalTo(widget.getId())));
}