DocumentReference extends EntityReference { public SpaceReference getLastSpaceReference() { return (SpaceReference) extractReference(EntityType.SPACE); } DocumentReference(EntityReference reference);  DocumentReference(String wikiName, String spaceName, String pageName);  DocumentReference(String wikiName, List<String> spaceNames, String pageName);  DocumentReference(String pageName, SpaceReference parent); @Override void setParent(EntityReference parent); @Override void setType(EntityType type); WikiReference getWikiReference(); void setWikiReference(WikiReference newWikiReference); SpaceReference getLastSpaceReference(); List<SpaceReference> getSpaceReferences();  }
@Test public void testGetLastSpaceReferenceWhenOneSpace() { DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); SpaceReference spaceReference = documentReference.getLastSpaceReference(); Assert.assertEquals(new SpaceReference("space", new WikiReference("wiki")), spaceReference); }
@Test public void testGetLastSpaceReferenceWhenMultipleSpaces() { DocumentReference reference = new DocumentReference("wiki", Arrays.asList("space1", "space2"), "page"); Assert.assertEquals(new SpaceReference("space2", new SpaceReference("space1", new WikiReference("wiki"))), reference.getLastSpaceReference()); }