InMemoryPermissionsImpl implements PermissionsInterface { @Override public void selfDestruct(User user) { if (isSharing(user)) { throw new CustomWebApplicationException("The user is sharing at least one workflow and cannot be deleted.", HttpStatus.SC_BAD_REQUEST); } else { user.getEntries().stream().forEach(e -> { if (e instanceof Workflow) { resourceToUsersAndRolesMap.remove(((Workflow)e).getWorkflowPath()); } }); } }  @Override List<Permission> setPermission(User requester, Workflow workflow, Permission permission); @Override Map<Role, List<String>> workflowsSharedWithUser(User user); @Override List<Permission> getPermissionsForWorkflow(User user, Workflow workflow); @Override List<Role.Action> getActionsForWorkflow(User user, Workflow workflow); @Override void removePermission(User user, Workflow workflow, String email, Role role); @Override boolean canDoAction(User user, Workflow workflow, Role.Action action); @Override void selfDestruct(User user); @Override boolean isSharing(User user);  }
@Test public void testSelfDestruct() { Assert.assertFalse(inMemoryPermissions.isSharing(johnDoeUser)); inMemoryPermissions.selfDestruct(johnDoeUser); inMemoryPermissions.setPermission(johnDoeUser, fooWorkflow, new Permission("jane", Role.OWNER)); thrown.expect(CustomWebApplicationException.class); inMemoryPermissions.selfDestruct(johnDoeUser); }