### Question:
DefaultRegionWidgetService implements RegionWidgetService { @Override @Synchronized(discriminator = "'RegionWidget'", id = "#regionWidgetId") @Transactional public RegionWidgetPreference saveRegionWidgetPreference(String regionWidgetId, RegionWidgetPreference preference) { RegionWidget regionWidget = this.getValidRegionWidget(regionWidgetId); ModelUtils.normalizeRegionWidgetPreference(regionWidgetId, preference); reconcileRegionWidgetPreferences(regionWidget.getPreferences(), Arrays.asList(preference), false); regionWidget = this.saveRegionWidget(regionWidget); for (RegionWidgetPreference regionWidgetPreference : regionWidget.getPreferences()) { if (regionWidgetPreference.getName().equals(preference.getName())) { preference = regionWidgetPreference; break; } } return preference; } @Autowired  DefaultRegionWidgetService(RegionWidgetRepository regionWidgetRepository); @Override RegionWidget getRegionWidget(String regionWidgetId); @Override SearchResult<RegionWidget> getAll(); @Override SearchResult<RegionWidget> getLimitedList(int offset, int pageSize); @Override @Transactional RegionWidget saveRegionWidget(RegionWidget regionWidget); @Override @Synchronized(discriminator = "'RegionWidget'", id = "#regionWidgetId") @Transactional List<RegionWidgetPreference> saveRegionWidgetPreferences(String regionWidgetId,
                                                                    List<RegionWidgetPreference> preferences); @Override @Synchronized(discriminator = "'RegionWidget'", id = "#regionWidgetId") @Transactional RegionWidgetPreference saveRegionWidgetPreference(String regionWidgetId, RegionWidgetPreference preference); @Override @Transactional RegionWidget saveRegionWidgetCollapsedState(String regionWidgetId, boolean collapsed);  }### Answer:
@Test public void saveRegionWidgetPreference() { final RegionWidget VALID_REGION_WIDGET = new RegionWidgetImpl(VALID_REGION_WIDGET_ID); VALID_REGION_WIDGET.setPreferences(getTestExistingRegionWidgetPreferences()); expect(regionWidgetRepository.get(VALID_REGION_WIDGET_ID)).andReturn(VALID_REGION_WIDGET).anyTimes(); expect(regionWidgetRepository.save(VALID_REGION_WIDGET)).andReturn(VALID_REGION_WIDGET).anyTimes(); replay(regionWidgetRepository); RegionWidgetPreference newPreference = new RegionWidgetPreferenceImpl(null, "age", "30"); RegionWidgetPreference savedNewPreference = regionWidgetService.saveRegionWidgetPreference(VALID_REGION_WIDGET_ID, newPreference); RegionWidgetPreference updatedPreference = new RegionWidgetPreferenceImpl(null, "color", "purple"); RegionWidgetPreference savedUpdatedPreference = regionWidgetService.saveRegionWidgetPreference(VALID_REGION_WIDGET_ID, updatedPreference); List<RegionWidgetPreference> existingPreferences = getTestExistingRegionWidgetPreferences(); existingPreferences.add(savedNewPreference); existingPreferences.get(0).setValue("purple"); assertTrue(preferenceCollectionsMatch(existingPreferences, VALID_REGION_WIDGET.getPreferences())); assertTrue(preferencesHaveValidRegionWidgetId(VALID_REGION_WIDGET.getPreferences())); }