### Question:
AttachURIVfsResourceReferenceSerializer implements ResourceReferenceSerializer<VfsResourceReference, URI> { @Override public URI serialize(VfsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); String scheme = reference.getScheme(); String documentRefefenceString = this.documentSerializer.serialize(attachmentReference.getDocumentReference()); try { String attachmentName = URIUtil.encodePath(attachmentReference.getName()); String referencePath = URIUtil.encodePath(reference.getPath()); return URI.create(String.format("%s: attachmentName, referencePath)); } catch (URIException e) { throw new SerializeResourceReferenceException( String.format("Error when encoding resource reference [%s]", reference.toString()), e); } }  @Override URI serialize(VfsResourceReference reference);  }### Answer:
@Test public void serialize() throws Exception { VfsResourceReference reference = new VfsResourceReference( URI.create("attach:xwiki:Toto.WebHome@testvfs.zip"), "path1/path2/test.txt"); AttachmentReference attachmentReference = new AttachmentReference("testvfs.zip", new DocumentReference("xwiki", Arrays.asList("Toto"), "WebHome")); when(attachmentReferenceResolver.resolve("xwiki:Toto.WebHome@testvfs.zip")).thenReturn(attachmentReference); when(entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())) .thenReturn("xwiki:Toto.WebHome"); assertEquals("attach: vfsResourceReferenceSerializer.serialize(reference).toString()); }
@Test public void serializeWithSpace() throws Exception { VfsResourceReference reference = new VfsResourceReference( URI.create("attach:xwiki:Toto.WebHome@testvfs.zip"), "path1/path2/xwiki logo.png"); AttachmentReference attachmentReference = new AttachmentReference("testvfs.zip", new DocumentReference("xwiki", Arrays.asList("Toto"), "WebHome")); when(attachmentReferenceResolver.resolve("xwiki:Toto.WebHome@testvfs.zip")).thenReturn(attachmentReference); when(entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())) .thenReturn("xwiki:Toto.WebHome"); assertEquals("attach: vfsResourceReferenceSerializer.serialize(reference).toString()); }