RemovePageTagsAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { return "Unable to find a page for resource " + resource.getPath(); } Tag[] oldTags = page.getTags(); List<Tag> tagsToSet = getTagsToSet(oldTags); String successMessage = "Set page tags on " + page.getPath() + ": " + getTagListAsString(tagsToSet); if (context.isDryRun()) { return successMessage; } TagManager tagManager = context.getTagManager(); tagManager.setTags(page.getContentResource(), tagsToSet.toArray(new Tag[tagsToSet.size()])); return successMessage; } RemovePageTagsAction(BindingContext context, String... tags); @Override String doAction(Resource resource);  }
@Test(expected = PersistenceException.class) public void doAction_invalidTag() throws PersistenceException { action = new RemovePageTagsAction(context, "invalid"); action.doAction(resource); }
@Test public void doAction() throws PersistenceException { action.doAction(resource); verify(tagManager, times(1)).setTags(resource, new Tag[] {tag3}); }