WidgetRepository extends AbstractRepository<Widget> { public List<Property> updateProperty(String widgetId, String propertyName, Property property) { Widget widget = get(widgetId); Property existingProperty = widget.getProperty(propertyName); if (existingProperty == null) { throw new NotFoundException(format("Widget [ %s ] has no property named %s", widgetId, propertyName)); } widget.replaceProperty(existingProperty, property); updateLastUpdateAndSave(widget); return widget.getProperties(); } @Inject  WidgetRepository(
            @Named("widgetPath") Path path,
            @Named("widgetFileBasedPersister") JsonFileBasedPersister<Widget> fileBasedRepository,
            @Named("widgetFileBasedLoader") JsonFileBasedLoader<Widget> widgetLoader,
            BeanValidator validator,
            Watcher watcher); @Override String getComponentName(); @Override void delete(String widgetId); Widget create(Widget widget); List<Widget> getByIds(Set<String> widgetIds); List<Property> addProperty(String widgetId, Property property); List<Property> updateProperty(String widgetId, String propertyName, Property property); List<Property> deleteProperty(String widgetId, String propertyName);  }
@Test public void should_update_an_existing_property() throws Exception { Property initialParam = aProperty().name("propertyName").label("propertyLabel").build(); Property updatedParam = aProperty().name("newName").label("newLablel").build(); Widget aWidget = addToRepository(aWidget().custom().property(initialParam).build()); widgetRepository.updateProperty(aWidget.getId(), initialParam.getName(), updatedParam); Widget widget = getFromRepository(aWidget.getId()); assertThat(widget.getProperties()).contains(updatedParam); assertThat(widget.getProperties()).doesNotContain(initialParam); }
@Test(expected = NotFoundException.class) public void should_fail_when_trying_to_update_a_not_existing_property() throws Exception { Widget expectedWidget = addToRepository(aWidget().custom().build()); widgetRepository.updateProperty(expectedWidget.getId(), "notExistingProperty", new Property()); }