### Question:
DocumentDocumentReferenceUserReferenceSerializer implements UserReferenceSerializer<DocumentReference> { @Override public DocumentReference serialize(UserReference userReference) { DocumentReference result; if (SuperAdminUserReference.INSTANCE == userReference) { result = new DocumentReference( this.entityReferenceProvider.getDefaultReference(EntityType.WIKI).getName(), XWIKI_SPACE, "superadmin"); } else if (GuestUserReference.INSTANCE == userReference) { result = new DocumentReference( this.entityReferenceProvider.getDefaultReference(EntityType.WIKI).getName(), XWIKI_SPACE, "XWikiGuest"); } else { UserReference normalizedUserReference = userReference; if (normalizedUserReference == null || CurrentUserReference.INSTANCE == normalizedUserReference) { normalizedUserReference = this.currentUserReferenceUserReferenceResolver.resolve(null); } if (!(normalizedUserReference instanceof DocumentUserReference)) { throw new IllegalArgumentException(String.format("Passed user reference must be of type [%s]", DocumentUserReference.class.getName())); } result = ((DocumentUserReference) normalizedUserReference).getReference(); } return result; }  @Override DocumentReference serialize(UserReference userReference);  }### Answer:
@Test void serializeWhenSuperAdmin() { DocumentReference expected = new DocumentReference("xwiki", "XWiki", "superadmin"); assertEquals(expected, this.serializer.serialize(SuperAdminUserReference.INSTANCE)); }
@Test void serializeWhenGuest() { DocumentReference expected = new DocumentReference("xwiki", "XWiki", "XWikiGuest"); assertEquals(expected, this.serializer.serialize(GuestUserReference.INSTANCE)); }
@Test void serializeWhenNull() { DocumentUserReference currentUserReference = mock(DocumentUserReference.class); DocumentReference currentDocumentReference = new DocumentReference("xwiki", "XWiki", "user"); when(currentUserReference.getReference()).thenReturn(currentDocumentReference); when(this.currentUserReferenceUserReferenceResolver.resolve(null)).thenReturn(currentUserReference); assertEquals(currentDocumentReference, this.serializer.serialize(null)); }
@Test void serializeWhenNotDocumentUserReference() { UserReference userReference = mock(UserReference.class); Throwable exception = assertThrows(RuntimeException.class, () -> this.serializer.serialize(userReference)); assertEquals("Passed user reference must be of type [org.xwiki.user.internal.document.DocumentUserReference]", exception.getMessage()); }