@Test public void testSiteRemoveException() throws ServletException, IOException, RepositoryException { Node site = mock(Node.class); when(site.getSession()).thenReturn(session); when(session.hasPendingChanges()).thenReturn(true); doThrow(new RepositoryException()).when(session).save(); when(resource.adaptTo(Node.class)).thenReturn(site); when(siteService.isSite(any(Item.class))).thenReturn(true); servlet.doPost(request, response); verify(response).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }