@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()); }
@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; }
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; } }
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; }  }
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); }
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);  }