### Question:
UnpublishPostOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { response.setPath(request.getResource().getPath()); publicationManagerFactory.getPublicationManager() .unpublish(request.getResource().adaptTo(PublishableResource.class)); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.onModified(request.getResource().getPath()); } catch (Exception e) { log.error("Failed to publish", e); response.setError(e); } }  @Override void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors);  }### Answer:
@Test public void testUnpublish() throws PublicationException { PublicationManagerFactory publicationManagerFactory = Mockito.mock(PublicationManagerFactory.class); PublicationManager publicationManager = Mockito.mock(PublicationManager.class); Mockito.when(publicationManagerFactory.getPublicationManager()).thenReturn(publicationManager); context.registerService(PublicationManagerFactory.class, publicationManagerFactory); UnpublishPostOperation unpublishPostOperation = context.registerInjectActivateService(new UnpublishPostOperation()); PostResponse response = Mockito.mock(PostResponse.class); unpublishPostOperation.run(context.request(), response, null); Mockito.verify(publicationManager).unpublish(Mockito.any()); Mockito.verify(response, Mockito.never()).setError(Mockito.any()); Mockito.verify(response).setPath(context.currentResource().getPath()); }
@Test public void testUnpublishFailure() throws PublicationException { PublicationManagerFactory publicationManagerFactory = Mockito.mock(PublicationManagerFactory.class); PublicationManager publicationManager = Mockito.mock(PublicationManager.class); PublicationException ex = new PublicationException("OH NO MR BILL"); Mockito.doThrow(ex).when(publicationManager).unpublish(Mockito.any()); Mockito.when(publicationManagerFactory.getPublicationManager()).thenReturn(publicationManager); context.registerService(PublicationManagerFactory.class, publicationManagerFactory); UnpublishPostOperation unpublishPostOperation = context.registerInjectActivateService(new UnpublishPostOperation()); PostResponse response = Mockito.mock(PostResponse.class); unpublishPostOperation.run(context.request(), response, null); Mockito.verify(response).setError(ex); }