@Test
public void testSerializeDocumentReference() throws Exception
{

    EntityReference reference = resolver.resolve("wiki:space.page", EntityType.DOCUMENT);
    Assert.assertEquals("wiki:space.page", serializer.serialize(reference));
    reference = resolver.resolve("wiki:space.", EntityType.DOCUMENT);
    Assert.assertEquals("wiki:space.WebHome", serializer.serialize(reference));
    reference = resolver.resolve("space.", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:space.WebHome", serializer.serialize(reference));
    reference = resolver.resolve("page", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.page", serializer.serialize(reference));
    reference = resolver.resolve(".", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.WebHome", serializer.serialize(reference));
    reference = resolver.resolve(null, EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.WebHome", serializer.serialize(reference));
    reference = resolver.resolve("", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.WebHome", serializer.serialize(reference));
    reference = resolver.resolve("wiki1.wiki2:wiki3:some.space.page", EntityType.DOCUMENT);
    Assert.assertEquals("wiki1.wiki2:wiki3:some\\.space.page", serializer.serialize(reference));
    reference = resolver.resolve("some.space.page", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:some\\.space.page", serializer.serialize(reference));
    reference = resolver.resolve("wiki:page", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.wiki:page", serializer.serialize(reference));
    // Verify that passing null doesn't throw a NPE
    Assert.assertNull(serializer.serialize(null));
    
    // Test escapes
    reference = resolver.resolve("\\.:@\\.", EntityType.DOCUMENT);
    Assert.assertEquals("xwiki:XWiki.\\.:@\\.", serializer.serialize(reference));
}