DefaultCapabilityRegistry extends ComponentSupport implements CapabilityRegistry, EventAware, EventAware.Asynchronous { @Override public CapabilityReference remove(final CapabilityIdentity id) { try { lock.writeLock().lock(); validateId(id); capabilityStorage.remove(id); return doRemove(id); } finally { lock.writeLock().unlock(); } } @Inject  DefaultCapabilityRegistry(final CapabilityStorage capabilityStorage,
                            final CapabilityFactoryRegistry capabilityFactoryRegistry,
                            final CapabilityDescriptorRegistry capabilityDescriptorRegistry,
                            final EventManager eventManager,
                            final ActivationConditionHandlerFactory activationConditionHandlerFactory,
                            final ValidityConditionHandlerFactory validityConditionHandlerFactory,
                            final PasswordHelper passwordHelper,
                            final Provider<Validator> validatorProvider); @Override CapabilityReference add(final CapabilityType type,
                                 final boolean enabled,
                                 @Nullable final String notes,
                                 @Nullable final Map<String, String> properties); @Subscribe void on(final CapabilityStorageItemCreatedEvent event); @Override CapabilityReference update(final CapabilityIdentity id,
                                    final boolean enabled,
                                    @Nullable final String notes,
                                    @Nullable final Map<String, String> properties); @Subscribe void on(final CapabilityStorageItemUpdatedEvent event); @Override CapabilityReference remove(final CapabilityIdentity id); @Subscribe void on(final CapabilityStorageItemDeletedEvent event); @Override CapabilityReference enable(final CapabilityIdentity id); @Override CapabilityReference disable(final CapabilityIdentity id); @Override DefaultCapabilityReference get(final CapabilityIdentity id); @Override Collection<DefaultCapabilityReference> get(final Predicate<CapabilityReference> filter); @Override Collection<DefaultCapabilityReference> getAll(); void load();  }
@Test public void remove() throws Exception { final CapabilityReference reference = underTest.add(CAPABILITY_TYPE, true, null, null); final CapabilityReference reference1 = underTest.remove(reference.context().id()); assertThat(reference1, is(equalTo(reference))); verify(eventManager, atLeastOnce()).post(rec.capture()); assertThat(rec.getAllValues().get(0), is(instanceOf(CapabilityEvent.Created.class))); assertThat(rec.getAllValues().get(0).getReference(), is(equalTo(reference1))); assertThat(rec.getAllValues().get(1), is(instanceOf(CapabilityEvent.AfterRemove.class))); assertThat(rec.getAllValues().get(1).getReference(), is(equalTo(reference1))); }