### Question:
SecurityReference extends EntityReference { public Deque<SecurityReference> getReversedSecurityReferenceChain() { Deque<SecurityReference> referenceList = new LinkedList<SecurityReference>(); SecurityReference reference = this; do { referenceList.push(reference); reference = reference.getParentSecurityReference(); } while (reference != null); return referenceList; } SecurityReference(EntityReference reference);   SecurityReference(EntityReference reference, SecurityReference mainWiki); SecurityReference getParentSecurityReference(); Deque<SecurityReference> getReversedSecurityReferenceChain(); EntityType getSecurityType(); SecurityReference getWikiReference(); EntityReference getOriginalReference(); WikiReference getOriginalWikiReference(); SpaceReference getOriginalSpaceReference(); DocumentReference getOriginalDocumentReference(); static final EntityType FARM; }### Answer:
@Test public void testGetReversedSecurityReferenceChain() throws Exception { List<SecurityReference> subList = (List<SecurityReference>) factory.newEntityReference(subEntity).getReversedSecurityReferenceChain(); assertThat(subList.get(0), equalTo(xwiki)); assertThat(subList.get(0).getOriginalReference(), equalTo(xwiki)); assertThat(subList.get(1), equalTo(wiki)); assertThat(subList.get(1).getOriginalReference(), equalTo(wiki)); assertThat(subList.get(2), equalTo(space)); assertThat(subList.get(2).getOriginalReference(), equalTo(space)); assertThat(subList.get(3), equalTo(subEntity)); assertThat(subList.get(3).getOriginalReference(), equalTo(subEntity)); List<SecurityReference> mainList = (List<SecurityReference>) factory.newEntityReference(mainEntity).getReversedSecurityReferenceChain(); assertThat(mainList.get(0), equalTo(xwiki)); assertThat(mainList.get(0).getOriginalReference(), equalTo(xwiki)); assertThat(mainList.get(1), equalTo(xspace)); assertThat(mainList.get(1).getOriginalReference(), equalTo(xspace)); assertThat(mainList.get(2), equalTo(mainEntity)); assertThat(mainList.get(2).getOriginalReference(), equalTo(mainEntity)); }