ContextId { @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() == obj.getClass()) { ContextId other = (ContextId) obj; return equals(other); } if (Map.class.isInstance(obj)) { Map<?, ?> metadata = (Map<?, ?>) obj; return toMetaData().equals(metadata); } if (obj instanceof String) { return toString().equals(obj); } return false; } ContextId(String id); String getId(); void setId(String id); Map<String, String> toMetaData(); static ContextId fromMetaData(Map<String, String> metaData); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static Map<String, String> getContextIdWildCard(); static final String META_KEY_ID; }
@Test public void testEquals_shouldBeTrueForEqualIds() throws Exception { ContextId id1 = new ContextId("theId"); ContextId id2 = new ContextId("theId"); assertThat(id1.equals(id2), is(true)); assertThat(id2.equals(id1), is(true)); }