### Question:
DbEntity extends Entity implements ConfigurationNode, DbEntityListener, DbAttributeListener,
        DbRelationshipListener { @Override public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate) { encoder.start("db-entity").attribute("name", getName()); if (getSchema() != null && getSchema().trim().length() > 0) { encoder.attribute("schema", getSchema().trim()); } if (getCatalog() != null && getCatalog().trim().length() > 0) { encoder.attribute("catalog", getCatalog().trim()); } encoder.nested(new TreeMap<>(getAttributeMap()), delegate); if (getPrimaryKeyGenerator() != null) { getPrimaryKeyGenerator().encodeAsXML(encoder, delegate); } if (getQualifier() != null) { encoder.start("qualifier"); getQualifier().encodeAsXML(encoder, delegate); encoder.end(); } delegate.visitDbEntity(this); encoder.end(); } DbEntity();  DbEntity(String name); @Override DbRelationship getRelationship(String relName); @Override DbAttribute getAttribute(String attributeName); @Override T acceptVisitor(ConfigurationNodeVisitor<T> visitor); @Override void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate); String getFullyQualifiedName(); String getSchema(); void setSchema(String schema); String getCatalog(); void setCatalog(String catalog); List<DbAttribute> getPrimaryKeys(); @SuppressWarnings("unchecked") @Override Collection<DbAttribute> getAttributes(); Collection<DbAttribute> getGeneratedAttributes(); void addAttribute(DbAttribute attr); @Override void removeAttribute(String attrName); @Override void clearAttributes(); @SuppressWarnings("unchecked") @Override Collection<DbRelationship> getRelationships(); @SuppressWarnings("unchecked") @Override Map<String, DbRelationship> getRelationshipMap(); @Override @SuppressWarnings("unchecked") PathComponent<DbAttribute, DbRelationship> lastPathComponent(Expression path, Map aliasMap); @Override @SuppressWarnings("unchecked") Iterable<PathComponent<DbAttribute, DbRelationship>> resolvePath(final Expression pathExp, final Map aliasMap); @Override Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp); void setPrimaryKeyGenerator(DbKeyGenerator primaryKeyGenerator); DbKeyGenerator getPrimaryKeyGenerator(); void dbEntityChanged(EntityEvent e); void dbEntityAdded(EntityEvent e); void dbEntityRemoved(EntityEvent e); void dbAttributeAdded(AttributeEvent e); void dbAttributeChanged(AttributeEvent e); void dbAttributeRemoved(AttributeEvent e); void dbRelationshipChanged(RelationshipEvent e); void dbRelationshipAdded(RelationshipEvent e); void dbRelationshipRemoved(RelationshipEvent e); Expression getQualifier(); void setQualifier(Expression qualifier); boolean isFullReplacementIdAttached(ObjectId id); Collection<ObjEntity> mappedObjEntities(); @Override Expression translateToRelatedEntity(Expression expression, String relationshipPath);  }### Answer:
@Test public void testEncodeAsXML() { DbEntity entity = new DbEntity("X"); entity.setSchema("s"); entity.setCatalog("c"); entity.addAttribute(new DbAttribute("a2", Types.VARCHAR, entity)); entity.addAttribute(new DbAttribute("a1", Types.INTEGER, entity)); entity.addAttribute(new DbAttribute("a3", Types.BIGINT, entity)); entity.addRelationship(new DbRelationship("r1")); StringWriter out = new StringWriter(); XMLEncoder encoder = new XMLEncoder(new PrintWriter(out)); entity.encodeAsXML(encoder, new EncoderDummyVisitor()); String ls = System.lineSeparator(); assertEquals("<db-entity name=\"X\" schema=\"s\" catalog=\"c\">" + ls + "<db-attribute name=\"a1\" type=\"INTEGER\"/>" + ls + "<db-attribute name=\"a2\" type=\"VARCHAR\"/>" + ls + "<db-attribute name=\"a3\" type=\"BIGINT\"/>" + ls + "</db-entity>" + ls, out.toString()); }