WidgetRepository extends AbstractRepository<Widget> { @Override public void delete(String widgetId) throws RepositoryException, NotAllowedException, InUseException { Widget widget = get(widgetId); if (!widget.isCustom()) { throw new NotAllowedException("We can only delete a custom widget"); } super.delete(widgetId); } @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_custom_widget() throws Exception { Widget customLabel = aWidget().id("customLabel").build(); customLabel.setController("$scope.hello = 'Hello'"); customLabel.setTemplate("<div>{{ hello + 'there'}}</div>"); customLabel.setCustom(true); createDirectories(widgetDirectory.resolve("customLabel")); widgetRepository.updateLastUpdateAndSave(customLabel); write(widgetDirectory.resolve("customLabel").resolve("customLabel.js"), objectMapper.toJson("")); widgetRepository.delete("customLabel"); assertThat(jsonFile(customLabel)).doesNotExist(); assertThat(jsFile(customLabel)).doesNotExist(); }
@Test(expected = NotAllowedException.class) public void should_not_allow_to_delete_a_pb_widget() throws Exception { Widget pbLabel = aWidget().id("pbLabel").build(); pbLabel.setCustom(false); addToRepository(pbLabel); widgetRepository.delete("pbLabel"); }