Category { @Override public boolean equals(Object category) { if (category instanceof Category) { Category cat = (Category) category; return this.getName() == null ? cat.getName() == null : this.getName().equalsIgnoreCase(cat.getName()); } else { return false; } }  abstract String getName(); @Override boolean equals(Object category); @Override int hashCode();  }
@Test public void test() { Category c1 = new Category() { @Override public String getName() { return cat1Name; } }; Category c2 = new Category() { @Override public String getName() { return cat2Name; } }; assertEquals(shouldBeEqual, c1.equals(c2)); }