### Question:
CurrentUserManager implements UserManager { @Override public boolean exists(UserReference userReference) { boolean exists; DocumentReference currentUserReference = getXWikiContext().getUserReference(); if (currentUserReference == null) { exists = false; } else { UserReference resolvedUserReference = this.userReferenceResolver.resolve(currentUserReference); if (SuperAdminUserReference.INSTANCE == resolvedUserReference || GuestUserReference.INSTANCE == resolvedUserReference) { exists = false; } else { exists = this.documentUserManager.exists(resolvedUserReference); } } return exists; }  @Override boolean exists(UserReference userReference);  }### Answer:
@Test void existsWhenNoCurrentUser() { XWikiContext xcontext = mock(XWikiContext.class); when(xcontext.getUserReference()).thenReturn(null); when(this.contextProvider.get()).thenReturn(xcontext); when(this.userReferenceResolver.resolve(null)).thenReturn(CurrentUserReference.INSTANCE); assertFalse(this.manager.exists(CurrentUserReference.INSTANCE)); }
@Test void existsWhenCurrentUser() { XWikiContext xcontext = mock(XWikiContext.class); DocumentReference documentReference = new DocumentReference("wiki", "XWiki", "User"); when(xcontext.getUserReference()).thenReturn(documentReference); when(this.contextProvider.get()).thenReturn(xcontext); DocumentUserReference documentUserReference = new DocumentUserReference(documentReference, null); when(this.userReferenceResolver.resolve(documentReference)).thenReturn(documentUserReference); this.manager.exists(CurrentUserReference.INSTANCE); verify(this.documentUserManager).exists(documentUserReference); }
@Test void existsWhenCurrentUserIsSuperAdmin() { XWikiContext xcontext = mock(XWikiContext.class); DocumentReference documentReference = new DocumentReference("wiki", "XWiki", "superadmin"); when(xcontext.getUserReference()).thenReturn(documentReference); when(this.contextProvider.get()).thenReturn(xcontext); when(this.userReferenceResolver.resolve(documentReference)).thenReturn(SuperAdminUserReference.INSTANCE); assertFalse(this.manager.exists(CurrentUserReference.INSTANCE)); }
@Test void existsWhenCurrentUserIsGuest() { XWikiContext xcontext = mock(XWikiContext.class); DocumentReference documentReference = new DocumentReference("wiki", "XWiki", "xwikiguest"); when(xcontext.getUserReference()).thenReturn(documentReference); when(this.contextProvider.get()).thenReturn(xcontext); when(this.userReferenceResolver.resolve(documentReference)).thenReturn(GuestUserReference.INSTANCE); assertFalse(this.manager.exists(CurrentUserReference.INSTANCE)); }