WidgetRepository extends AbstractRepository<Widget> { public List<Property> deleteProperty(String widgetId, String propertyName) { Widget widget = get(widgetId); Property param = widget.getProperty(propertyName); if (param == null) { throw new NotFoundException(format("Widget [ %s ] has no property named %s", widgetId, propertyName)); } widget.deleteProperty(param); 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_delete_a_widget_property() throws Exception { Property aProperty = aProperty().name("aParam").build(); Widget aWidget = addToRepository(aWidget().property(aProperty).property(aProperty().name("anotherParam")).build()); List<Property> properties = widgetRepository.deleteProperty(aWidget.getId(), "aParam"); Widget widget = getFromRepository(aWidget.getId()); assertThat(widget.getProperties()).doesNotContain(aProperty); assertThat(properties).containsOnlyElementsOf(widget.getProperties()); }
@Test(expected = NotFoundException.class) public void should_fail_when_trying_to_delete_a_property_on_an_unknown_widget() throws Exception { widgetRepository.deleteProperty("unknownWidget", "aParam"); }
@Test(expected = NotFoundException.class) public void should_fail_when_trying_to_delete_an_unknown_property() throws Exception { Widget aWidget = addToRepository(aWidget().build()); widgetRepository.deleteProperty(aWidget.getId(), "unknownPrameter"); }