NameAwareAttribute implements Attribute, Iterable<Object> { @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; NameAwareAttribute that = (NameAwareAttribute) o; if (id != null ? !id.equals(that.id) : that.id != null) return false; if(this.values.size() != that.values.size()) { return false; } if(this.orderMatters != that.orderMatters || this.size() != that.size()) { return false; } if(this.hasValuesAsNames() != that.hasValuesAsNames()) { return false; } Set<?> myValues = this.values; Set<?> theirValues = that.values; if(this.hasValuesAsNames()) { myValues = this.valuesAsNames.keySet(); theirValues = that.valuesAsNames.keySet(); } if(orderMatters) { Iterator<?> thisIterator = myValues.iterator(); Iterator<?> thatIterator = theirValues.iterator(); while(thisIterator.hasNext()) { if(!ObjectUtils.nullSafeEquals(thisIterator.next(), thatIterator.next())) { return false; } } return true; } else { for (Object value : myValues) { if(!CollectionUtils.contains(theirValues.iterator(), value)) { return false; } } return true; } } NameAwareAttribute(String id, Object value);  NameAwareAttribute(Attribute attribute);  NameAwareAttribute(String id);  NameAwareAttribute(String id, boolean orderMatters); @Override NamingEnumeration<?> getAll(); @Override Object get(); @Override int size(); @Override String getID(); @Override boolean contains(Object attrVal); @Override boolean add(Object attrVal); void initValuesAsNames(); boolean hasValuesAsNames(); @Override boolean remove(Object attrval); @Override void clear(); @Override DirContext getAttributeSyntaxDefinition(); @Override DirContext getAttributeDefinition(); @Override boolean isOrdered(); @Override Object get(int ix); @Override Object remove(int ix); @Override void add(int ix, Object attrVal); @Override Object set(int ix, Object attrVal); @Override Object clone(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override Iterator<Object> iterator();  }
@Test public void testEqualsWithIdNotSame() { NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute"); NameAwareAttribute attr2 = new NameAwareAttribute("someOtherAttribute"); assertThat(attr1.equals(attr2)).isFalse(); }