### Question:
DbAttribute extends Attribute implements ConfigurationNode { public void setPrimaryKey(boolean primaryKey) { if (this.primaryKey != primaryKey) { this.primaryKey = primaryKey; Entity e = this.getEntity(); if (e instanceof DbAttributeListener) { ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent(this, this, e)); } } } DbAttribute();  DbAttribute(String name);  DbAttribute(String name, int type, DbEntity entity); @Override DbEntity getEntity(); T acceptVisitor(ConfigurationNodeVisitor<T> visitor); @Override void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate); String getAliasedName(String alias); int getType(); void setType(int type); boolean isPrimaryKey(); boolean isForeignKey(); void setPrimaryKey(boolean primaryKey); boolean isMandatory(); void setMandatory(boolean mandatory); int getMaxLength(); void setMaxLength(int maxLength); boolean isGenerated(); void setGenerated(boolean generated); int getAttributePrecision(); void setAttributePrecision(int attributePrecision); int getScale(); void setScale(int scale); @Override String toString();  }### Answer:
@Test public void testPrimaryKeyAdded() { DbEntity dbe = new DbEntity("e"); DbAttribute a = new DbAttribute("abc", Types.INTEGER, dbe); a.setPrimaryKey(true); dbe.addAttribute(a); Collection<DbAttribute> pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(1, pk.size()); }
@Test public void testPrimaryKeyAttributeChanged() { DbEntity dbe = new DbEntity("e"); DbAttribute a = new DbAttribute("abc", Types.INTEGER, dbe); dbe.addAttribute(a); Collection<DbAttribute> pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(0, pk.size()); a.setPrimaryKey(true); pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(1, pk.size()); }
@Test public void testPrimaryKeyRemoved() { DbEntity dbe = new DbEntity("e"); DbAttribute a = new DbAttribute("abc", Types.INTEGER, dbe); a.setPrimaryKey(true); dbe.addAttribute(a); Collection<DbAttribute> pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(1, pk.size()); dbe.removeAttribute(a.getName()); pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(0, pk.size()); }
@Test public void testAttributesCleared() { DbEntity dbe = new DbEntity("e"); DbAttribute a = new DbAttribute("abc", Types.INTEGER, dbe); a.setPrimaryKey(true); dbe.addAttribute(a); Collection<DbAttribute> pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(1, pk.size()); dbe.clearAttributes(); pk = dbe.getPrimaryKeys(); assertNotNull(pk); assertEquals(0, pk.size()); }