PermissionsManager { public void remove(String userId, String domainId, String instanceId) throws ConflictException, ServerException, NotFoundException { final PermissionsDao<? extends AbstractPermissions> permissionsDao = getPermissionsDao(domainId); Permissions permissions; try (@SuppressWarnings("unused") Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) { if (userHasLastSetPermissions(permissionsDao, userId, instanceId)) { throw new ConflictException( "Can't remove permissions because there is not any another user " + "with permission 'setPermissions'"); } permissions = permissionsDao.get(userId, instanceId); permissionsDao.remove(userId, instanceId); } final String initiator = EnvironmentContext.getCurrent().getSubject().getUserName(); eventService.publish(new PermissionsRemovedEvent(initiator, permissions)); } @Inject  PermissionsManager(
      EventService eventService, Set<PermissionsDao<? extends AbstractPermissions>> daos); void storePermission(Permissions permissions); AbstractPermissions get(String userId, String domainId, String instanceId); @SuppressWarnings("unchecked") Page<AbstractPermissions> getByInstance(
      String domainId, String instanceId, int maxItems, long skipCount); void remove(String userId, String domainId, String instanceId); boolean exists(String userId, String domainId, String instanceId, String action); void checkActionsSupporting(String domainId, List<String> actions); List<AbstractPermissionsDomain> getDomains(); AbstractPermissionsDomain<? extends AbstractPermissions> getDomain(String domain);  }
@Test public void shouldBeAbleToDeletePermissions() throws Exception { permissionsManager.remove("user", "test", "test123"); verify(permissionsDao).remove(eq("user"), eq("test123")); }