AccumulatorRequest { @Override public int hashCode() { return getName().hashCode(); } AccumulatorRequest(String name, Class<?> clazz); String getName(); Class<?> getClazz(); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testHashCode() { AccumulatorRequest[] requests = { new AccumulatorRequest("hello", Long.class), new AccumulatorRequest("world", Long.class), new AccumulatorRequest("goodbye", Double.class), new AccumulatorRequest("void", Double.class), new AccumulatorRequest("hello", Long.class), new AccumulatorRequest("anotherworld", Double.class) }; for (AccumulatorRequest request : requests) { for (AccumulatorRequest other : requests) { if (request.equals(other)) { assertEquals("Hash codes for accumulators "+request.getName()+" and "+other.getName()+" are not equal", request.hashCode(), other.hashCode()); } else { assertNotEquals("Hash codes for accumulators "+request.getName()+" and "+other.getName()+" are equal", request.hashCode(), other.hashCode()); } } } }