AbstractCollectionCacheKeyGenerator extends AbstractCacheKeyGenerator { @Override public int hashCode() { int result = getClass().hashCode(); result = result * 31 + Boolean.valueOf(isProvisional()).hashCode(); if (getCollection() != null) { result = result * 31 + getCollection().hashCode(); } return result; }  ICacheKeyGenerator combine(ICacheKeyGenerator otherKeyGen); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void testHashCode() { TestCollectionCacheKeyGenerator gen1 = new TestCollectionCacheKeyGenerator(new HashSet<String>(Arrays.asList("a", "b")), false); TestCollectionCacheKeyGenerator gen2 = new TestCollectionCacheKeyGenerator(new HashSet<String>(Arrays.asList("a", "b")), false); TestCollectionCacheKeyGenerator gen3 = new TestCollectionCacheKeyGenerator(new HashSet<String>(Arrays.asList("a", "b")), true); TestCollectionCacheKeyGenerator gen4 = new TestCollectionCacheKeyGenerator(new HashSet<String>(Arrays.asList("b", "c")), false); TestCollectionCacheKeyGenerator nulcol1 = new TestCollectionCacheKeyGenerator(null, true); TestCollectionCacheKeyGenerator nulcol2 = new TestCollectionCacheKeyGenerator(null, true); TestCollectionCacheKeyGenerator nulcol3 = new TestCollectionCacheKeyGenerator(null, false); Assert.assertTrue(gen1.hashCode() == gen2.hashCode()); Assert.assertFalse(gen1.hashCode() == gen3.hashCode()); Assert.assertFalse(gen1.hashCode() == gen4.hashCode()); Assert.assertTrue(nulcol1.hashCode() == nulcol2.hashCode()); Assert.assertFalse(nulcol1.hashCode() == nulcol3.hashCode()); Assert.assertFalse(gen1.hashCode() == nulcol1.hashCode()); Assert.assertFalse(gen1.hashCode() == nulcol3.hashCode()); Assert.assertFalse(gen3.hashCode() == nulcol1.hashCode()); Assert.assertFalse(gen3.hashCode() == nulcol3.hashCode()); }