### Question:
DefaultModelBridge implements ModelBridge { protected boolean canRestoreDeletedDocument(XWikiDeletedDocument deletedDocument, DocumentReference userReference) { boolean result = false; XWikiContext context = this.xcontextProvider.get(); DocumentReference currentUserReference = context.getUserReference(); try { DeletedDocument deletedDocumentApi = new DeletedDocument(deletedDocument, context); context.setUserReference(userReference); result = deletedDocumentApi.canUndelete(); } catch (Exception e) { logger.error("Failed to check restore rights on deleted document [{}] for user [{}]", deletedDocument.getId(), userReference, e); } finally { context.setUserReference(currentUserReference); } return result; }  @Override boolean create(DocumentReference documentReference); @Override boolean copy(DocumentReference source, DocumentReference destination); @Override boolean delete(DocumentReference reference); @Override boolean delete(DocumentReference reference, boolean skipRecycleBin); @Override boolean removeLock(DocumentReference reference); @Override void createRedirect(DocumentReference oldReference, DocumentReference newReference); @Override boolean canOverwriteSilently(DocumentReference documentReference); @Override boolean exists(DocumentReference reference); @Override List<DocumentReference> getBackLinkedReferences(DocumentReference documentReference, String wikiId); @Override List<DocumentReference> getDocumentReferences(SpaceReference spaceReference); @Override boolean updateParentField(final DocumentReference oldParentReference,
        final DocumentReference newParentReference); @Override DocumentReference setContextUserReference(DocumentReference userReference); @Override void update(DocumentReference documentReference, Map<String, String> parameters); @Override boolean restoreDeletedDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override List<Long> getDeletedDocumentIds(String batchId); @Override boolean permanentlyDeleteDocument(long deletedDocumentId, AbstractCheckRightsRequest request); @Override boolean permanentlyDeleteAllDocuments(PermanentlyDeleteJob deleteJob, AbstractCheckRightsRequest request); @Override boolean rename(DocumentReference source, DocumentReference destination);  }### Answer:
@Test void canRestoreDeletedDocument() throws Exception { long deletedDocumentId = 42; String deletedDocumentFullName = "Space.DeletedDocument"; DocumentReference userReferenceToCheck = new DocumentReference("wiki", "Space", "User"); DocumentReference currentUserReference = new DocumentReference("wiki", "Space", "CurrentUser"); when(xcontext.getUserReference()).thenReturn(currentUserReference); XWikiDeletedDocument deletedDocument = mock(XWikiDeletedDocument.class); when(deletedDocument.getFullName()).thenReturn(deletedDocumentFullName); XWikiRightService rightService = mock(XWikiRightService.class); when(xwiki.getRightService()).thenReturn(rightService); when(rightService.hasAccessLevel(any(), any(), any(), any())).thenReturn(true); assertTrue(this.modelBridge.canRestoreDeletedDocument(deletedDocument, userReferenceToCheck)); verify(xcontext).setUserReference(userReferenceToCheck); verify(xcontext).setUserReference(currentUserReference); }