### Question:
UndeleteAction extends XWikiAction { @Override public boolean action(XWikiContext context) throws XWikiException { XWikiRequest request = context.getRequest(); XWikiResponse response = context.getResponse(); XWikiDocument doc = context.getDoc(); XWikiDeletedDocument deletedDocument = getDeletedDocument(context); if (deletedDocument == null) { sendRedirect(response, doc.getURL(VIEW_ACTION, context)); return false; } if (TRUE.equals(request.getParameter(SHOW_BATCH_PARAMETER)) && !TRUE.equals(request.getParameter(CONFIRM_PARAMETER))) { return true; } if (!csrfTokenCheck(context)) { return false; } DeletedDocument deletedDocumentAPI = new DeletedDocument(deletedDocument, context); if (!deletedDocumentAPI.canUndelete()) { return true; } boolean redirected = false; if (deletedDocument != null) { redirected = restoreDocument(deletedDocument, context); } if (!redirected) { String queryString = getRedirectQueryString(context, deletedDocument.getLocale()); sendRedirect(response, doc.getURL(VIEW_ACTION, queryString, context)); redirected = true; } return !redirected; }  @Override boolean action(XWikiContext context); @Override String render(XWikiContext context);  }### Answer:
@Test void restoreSingleDocument() throws Exception { when(this.csrfToken.isTokenValid(null)).thenReturn(true); when(this.oldcore.getMockRightService().hasAccessLevel(any(), any(), any(), any())).thenReturn(true); assertFalse(this.undeleteAction.action(this.oldcore.getXWikiContext())); verify(this.requestFactory).createRestoreRequest(Arrays.asList(ID)); verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest); verify(job).join(); }
@Test void restoreSingleDocumentWhenDeleter() throws Exception { when(this.csrfToken.isTokenValid(null)).thenReturn(true); when(this.oldcore.getMockAuthorizationManager().hasAccess(Right.EDIT, null, DELETED_REFERENCE)) .thenReturn(true); assertFalse(this.undeleteAction.action(this.oldcore.getXWikiContext())); verify(this.requestFactory).createRestoreRequest(Arrays.asList(ID)); verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest); verify(job).join(); }
@Test void missingCSRFToken() throws Exception { when(this.csrfToken.isTokenValid(null)).thenReturn(false); assertFalse(this.undeleteAction.action(this.oldcore.getXWikiContext())); verify(this.csrfToken).getResubmissionURL(); }
@Test void restoreBatch() throws Exception { when(this.csrfToken.isTokenValid(null)).thenReturn(true); String batchId = "abc123"; when(deletedDocument.getBatchId()).thenReturn(batchId); when(this.request.getParameter("showBatch")).thenReturn("true"); when(this.request.getParameter("includeBatch")).thenReturn("true"); when(this.request.getParameter("confirm")).thenReturn("true"); when(this.oldcore.getMockRightService().hasAccessLevel(any(), any(), any(), any())).thenReturn(true); assertFalse(this.undeleteAction.action(this.oldcore.getXWikiContext())); verify(this.requestFactory).createRestoreRequest(batchId); verify(jobExecutor).execute(RefactoringJobs.RESTORE, jobRequest); verify(job).join(); }