### Question:
NormalUserConfigurationSourceAuthorization extends AbstractDocumentConfigurationSourceAuthorization { @Override public boolean hasAccess(String key, UserReference userReference, ConfigurationRight right) { boolean hasAccess; XWikiContext xcontext = this.contextProvider.get(); XWikiDocument currentDocument = xcontext.getDoc(); if (currentDocument != null) { DocumentReference lastAuthorDocumentReference = xcontext.getAuthorReference(); DocumentReference originalUserReference = this.documentAccessBridge.getCurrentUserReference(); try { xcontext.setUserReference(((DocumentUserReference) userReference).getReference()); hasAccess = super.hasAccess(key, this.documentResolver.resolve(lastAuthorDocumentReference), right); } finally { xcontext.setUserReference(originalUserReference); } } else { hasAccess = super.hasAccess(key, this.currentResolver.resolve(null), right); } return hasAccess; }  @Override boolean hasAccess(String key, UserReference userReference, ConfigurationRight right);  }### Answer:
@Test void hasAccessREADWhenLastAuthorHasViewPermissionOnUserDoc() { when(this.authorizationManager.hasAccess(Right.VIEW, this.lastAuthorDocumentReference, this.userDocumentReference)).thenReturn(true); assertTrue(this.authorization.hasAccess("key", this.userReference, ConfigurationRight.READ)); InOrder inOrder = inOrder(this.xcontext); inOrder.verify(this.xcontext).setUserReference(this.userDocumentReference); inOrder.verify(this.xcontext).setUserReference(this.previousCurrentUserDocumentReference); }
@Test void hasAccessREADWhenNoLastAuthorHasNoViewPermissionOnUserDoc() { when(this.authorizationManager.hasAccess(Right.VIEW, this.lastAuthorDocumentReference, this.userDocumentReference)).thenReturn(false); assertFalse(this.authorization.hasAccess("key", userReference, ConfigurationRight.READ)); verify(this.xcontext).setUserReference(this.userDocumentReference); verify(this.xcontext).setUserReference(this.previousCurrentUserDocumentReference); }
@Test void hasAccessWRITEWhenLastAuthorHasEditPermissionOnUserDoc() { when(this.authorizationManager.hasAccess(Right.EDIT, this.lastAuthorDocumentReference, this.userDocumentReference)).thenReturn(true); assertTrue(this.authorization.hasAccess("key", this.userReference, ConfigurationRight.WRITE)); InOrder inOrder = inOrder(this.xcontext); inOrder.verify(this.xcontext).setUserReference(this.userDocumentReference); inOrder.verify(this.xcontext).setUserReference(this.previousCurrentUserDocumentReference); }
@Test void hasAccessWRITEWhenLastAuthorHasNoEditPermissionOnUserDoc() { when(this.authorizationManager.hasAccess(Right.EDIT, this.lastAuthorDocumentReference, this.userDocumentReference)).thenReturn(false); assertFalse(this.authorization.hasAccess("key", this.userReference, ConfigurationRight.WRITE)); InOrder inOrder = inOrder(this.xcontext); inOrder.verify(this.xcontext).setUserReference(this.userDocumentReference); inOrder.verify(this.xcontext).setUserReference(this.previousCurrentUserDocumentReference); }