assertTrue(preferencesHaveValidRegionWidgetId(savedPreferences));
}
@Test
public void saveRegionWidgetPreference() {
final RegionWidget VALID_REGION_WIDGET = new RegionWidget(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);
//Add and update a preference.
RegionWidgetPreference newPreference = new RegionWidgetPreference(null, null, "age", "30");
RegionWidgetPreference savedNewPreference = regionWidgetService.saveRegionWidgetPreference(VALID_REGION_WIDGET_ID, newPreference);
RegionWidgetPreference updatedPreference = new RegionWidgetPreference(null, null, "color", "purple");
RegionWidgetPreference savedUpdatedPreference = regionWidgetService.saveRegionWidgetPreference(VALID_REGION_WIDGET_ID, updatedPreference);
//Make sure the new and updated preference got mixed in properly with the existing preferences.
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()));
}