### Question:
RegionWidgetApi extends AbstractRestApi { @ResponseBody @RequestMapping(value = "/{regionWidgetId}/preferences", method = RequestMethod.PUT) public RegionWidgetPreferenceListWrapper replaceAllRegionWidgetPreferences(@PathVariable String regionWidgetId, @RequestBody RegionWidgetPreferenceListWrapper regionWidgetPreferenceListWrapper) { if (logger.isDebugEnabled()) { logger.debug("PUT received to replace all preferences for regionWidget: " + regionWidgetId + " with data: " + regionWidgetPreferenceListWrapper); } List<RegionWidgetPreference> regionWidgetPreferences = regionWidgetService.saveRegionWidgetPreferences( regionWidgetId, regionWidgetPreferenceListWrapper.getPreferences()); return new RegionWidgetPreferenceListWrapper(regionWidgetPreferences); } @Autowired  RegionWidgetApi(RegionWidgetService regionWidgetService); @ResponseBody @RequestMapping(value = "/{regionWidgetId}/preferences", method = RequestMethod.PUT) RegionWidgetPreferenceListWrapper replaceAllRegionWidgetPreferences(@PathVariable String regionWidgetId,
                                                                               @RequestBody RegionWidgetPreferenceListWrapper
                                                                                       regionWidgetPreferenceListWrapper); @ResponseBody @RequestMapping(value = "/{regionWidgetId}/preferences/{regionWidgetPreferenceName}", method = RequestMethod.PUT) RegionWidgetPreference createOrReplaceRegionWidgetPreference(@PathVariable String regionWidgetId,
                                                                        @PathVariable String regionWidgetPreferenceName,
                                                                        @RequestBody RegionWidgetPreference regionWidgetPreference); @ResponseBody @RequestMapping(value = "/{regionWidgetId}/collapsed", method = RequestMethod.PUT) RegionWidget updateRegionWidgetCollapsedStatus(@PathVariable String regionWidgetId,
                                                          @RequestBody Boolean collapsed);  }### Answer:
@Test public void replaceAllRegionWidgetPreferences_validParams() { RegionWidgetPreferenceListWrapper LIST_WRAPPER = new RegionWidgetPreferenceListWrapper(Arrays.asList( (RegionWidgetPreference) new RegionWidgetPreferenceImpl(), new RegionWidgetPreferenceImpl() )); expect(regionWidgetService.saveRegionWidgetPreferences(VALID_REGION_WIDGET_ID, LIST_WRAPPER.getPreferences())). andReturn(LIST_WRAPPER.getPreferences()); replay(regionWidgetService); RegionWidgetPreferenceListWrapper result = regionWidgetApi.replaceAllRegionWidgetPreferences(VALID_REGION_WIDGET_ID, LIST_WRAPPER); verify(regionWidgetService); assertThat(result.getPreferences(), sameInstance(LIST_WRAPPER.getPreferences())); }
@Test(expected = IllegalArgumentException.class) public void replaceAllRegionWidgetPreferences_invalidParams() { RegionWidgetPreferenceListWrapper LIST_WRAPPER = new RegionWidgetPreferenceListWrapper(Arrays.asList( (RegionWidgetPreference) new RegionWidgetPreferenceImpl(), new RegionWidgetPreferenceImpl() )); expect(regionWidgetService.saveRegionWidgetPreferences(INVALID_REGION_WIDGET_ID, LIST_WRAPPER.getPreferences())). andThrow(new IllegalArgumentException()); replay(regionWidgetService); regionWidgetApi.replaceAllRegionWidgetPreferences(INVALID_REGION_WIDGET_ID, LIST_WRAPPER); }