### Question:
EntityInheritanceTree { public ObjEntity entityMatchingRow(DataRow row) { if (subentities != null) { for (EntityInheritanceTree child : subentities) { ObjEntity matched = child.entityMatchingRow(row); if (matched != null) { return matched; } } } Expression qualifier = getDbQualifier(); if (qualifier != null) { return qualifier.match(row) ? entity : null; } return entity; } EntityInheritanceTree(ObjEntity entity); Expression qualifierForEntityAndSubclasses(); ObjEntity entityMatchingRow(DataRow row); Expression getDbQualifier(); void addChildNode(EntityInheritanceTree node); int getChildrenCount(); Collection<EntityInheritanceTree> getChildren(); ObjEntity getEntity(); Collection<ObjEntity> allSubEntities(); Collection<ObjAttribute> allAttributes(); Collection<ObjRelationship> allRelationships();  }### Answer:
@Test public void testEntityMatchingRow_NoInheritance() { DataMap dataMap = new DataMap("map"); DbEntity dbEntity = new DbEntity("e1"); dbEntity.addAttribute(new DbAttribute("x")); dataMap.addDbEntity(dbEntity); ObjEntity entity = new ObjEntity("E1"); entity.setDbEntityName(dbEntity.getName()); dataMap.addObjEntity(entity); EntityInheritanceTree t1 = new EntityInheritanceTree(entity); DataRow row11 = new DataRow(5); row11.put("x", 1); assertSame(entity, t1.entityMatchingRow(row11)); entity.setDeclaredQualifier(ExpressionFactory.matchDbExp("x", 2)); assertNull(t1.entityMatchingRow(row11)); DataRow row12 = new DataRow(5); row12.put("x", 2); assertSame(entity, t1.entityMatchingRow(row12)); }
@Test public void testEntityMatchingRow_SingleTableInheritance() { DataMap dataMap = new DataMap("map"); DbEntity dbEntity = new DbEntity("e1"); dbEntity.addAttribute(new DbAttribute("x")); dataMap.addDbEntity(dbEntity); ObjEntity entity = new ObjEntity("E1"); entity.setDbEntityName(dbEntity.getName()); entity.setDeclaredQualifier(ExpressionFactory.matchDbExp("x", 2)); dataMap.addObjEntity(entity); ObjEntity subEntity = new ObjEntity("E2"); subEntity.setSuperEntityName("E1"); subEntity.setDeclaredQualifier(ExpressionFactory.matchDbExp("x", 1)); dataMap.addObjEntity(subEntity); EntityResolver resolver = new EntityResolver(Collections.singleton(dataMap)); EntityInheritanceTree t1 = resolver.getInheritanceTree("E1"); DataRow row11 = new DataRow(5); row11.put("x", 1); DataRow row12 = new DataRow(5); row12.put("x", 2); DataRow row13 = new DataRow(5); row13.put("x", 3); assertSame(subEntity, t1.entityMatchingRow(row11)); assertSame(entity, t1.entityMatchingRow(row12)); assertNull(t1.entityMatchingRow(row13)); }