### Question:
EntityPathCache { PathDescriptor getPathDescriptor(final ASTObjPath path) { PathDescriptor entry = pathCache.get(path.getPath()); if (entry == null) { String stringPath = (String) path.getOperand(0); final Object last = lastPathComponent(entity, stringPath); if (last instanceof AgAttribute) { entry = new PathDescriptor() { AgAttribute attribute = (AgAttribute) last; @Override public boolean isAttribute() { return true; } @Override public Class<?> getType() { return attribute.getType(); } @Override public ASTPath getPathExp() { return path; } }; } else { entry = new PathDescriptor() { AgRelationship relationship = (AgRelationship) last; Class<?> type = relationship.getTargetEntity().getType(); @Override public boolean isAttribute() { return false; } @Override public Class<?> getType() { return type; } @Override public ASTPath getPathExp() { return path; } }; } pathCache.put(path.getPath(), entry); } return entry; } EntityPathCache(final AgEntity<?> entity);   }### Answer:
@Test public void testGetPathDescriptor_Attribute() { EntityPathCache cache = new EntityPathCache(metadataService.getAgEntity(X.class)); PathDescriptor pd = cache.getPathDescriptor(new ASTObjPath("name")); assertNotNull(pd); assertTrue(pd.isAttribute()); assertEquals(String.class, pd.getType()); assertEquals("name", pd.getPathExp().getPath()); assertSame(pd, cache.getPathDescriptor(new ASTObjPath("name"))); }
@Test public void testGetPathDescriptor_Relationship() { EntityPathCache cache = new EntityPathCache(metadataService.getAgEntity(X.class)); PathDescriptor pd = cache.getPathDescriptor(new ASTObjPath("y")); assertNotNull(pd); assertFalse(pd.isAttribute()); assertEquals(Y.class, pd.getType()); assertEquals("y", pd.getPathExp().getPath()); assertSame(pd, cache.getPathDescriptor(new ASTObjPath("y"))); }
@Test public void testGetPathDescriptor_RelatedAttribute() { EntityPathCache cache = new EntityPathCache(metadataService.getAgEntity(X.class)); PathDescriptor pd = cache.getPathDescriptor(new ASTObjPath("y.name")); assertNotNull(pd); assertTrue(pd.isAttribute()); assertEquals(String.class, pd.getType()); assertEquals("y.name", pd.getPathExp().getPath()); assertSame(pd, cache.getPathDescriptor(new ASTObjPath("y.name"))); }
@Test public void testGetPathDescriptor_BadPath() { EntityPathCache cache = new EntityPathCache(metadataService.getAgEntity(X.class)); assertThrows(AgException.class, () -> cache.getPathDescriptor(new ASTObjPath("y.xyz"))); }
@Test public void testGetPathDescriptor_OuterRelatedAttribute() { EntityPathCache cache = new EntityPathCache(metadataService.getAgEntity(X.class)); PathDescriptor pd = cache.getPathDescriptor(new ASTObjPath("y+.name")); assertNotNull(pd); assertTrue(pd.isAttribute()); assertEquals(String.class, pd.getType()); assertEquals("y+.name", pd.getPathExp().getPath()); assertSame(pd, cache.getPathDescriptor(new ASTObjPath("y+.name"))); assertNotSame(pd, cache.getPathDescriptor(new ASTObjPath("y.name"))); }