### Question:
EntityId { public Iterable<EntityId> getHierarchy() { if (hierarchy == null) { Vector<EntityId> hierarchy = new Vector<>(); EntityId current = this; while (current instanceof ParentedId) { hierarchy.insertElementAt(current, 0); current = ((ParentedId) current).getParent(); } hierarchy.insertElementAt(current, 0); this.hierarchy = hierarchy; } return hierarchy; } protected  EntityId(EntityType entity); static void ensureValidId(String propertyName, String name); static void ensureValidArtifactId(String propertyName, String name); static boolean isValidId(String name); static boolean isValidArtifactId(String name); static void ensureValidDatasetId(String propertyName, String datasetId); static boolean isValidDatasetId(String datasetId); static void ensureValidNamespace(String namespace); static boolean isValidNamespace(String namespace); static boolean isValidVersionId(String datasetId); abstract Iterable<String> toIdParts(); abstract String getEntityName(); MetadataEntity toMetadataEntity(); static T fromMetadataEntity(MetadataEntity metadataEntity); static T getSelfOrParentEntityId(MetadataEntity metadataEntity); final EntityType getEntityType(); static T fromString(String string); @Override final String toString(); @Override boolean equals(Object o); @Override int hashCode(); Iterable<EntityId> getHierarchy(); static final String IDSTRING_TYPE_SEPARATOR; static final String IDSTRING_PART_SEPARATOR; static final Pattern IDSTRING_PART_SEPARATOR_PATTERN; }### Answer:
@Test public void testHierarchy() { NamespaceId namespace = Ids.namespace("foo"); ApplicationId app = namespace.app("bar"); ProgramId program = app.service("foo"); List<EntityId> expectedHierarchy = new ArrayList<>(); expectedHierarchy.add(namespace); Assert.assertEquals(expectedHierarchy, namespace.getHierarchy()); expectedHierarchy.add(app); Assert.assertEquals(expectedHierarchy, app.getHierarchy()); expectedHierarchy.add(program); Assert.assertEquals(expectedHierarchy, program.getHierarchy()); }