CacheKeyFactory { public static Object createKey(Class<?> destClass, Class<?> srcClass) { return new CacheKey(srcClass, destClass); } private  CacheKeyFactory(); static Object createKey(Class<?> destClass, Class<?> srcClass); static Object createKey(Class<?> destClass, Class<?> srcClass, String mapId);  }
@Test public void canCreateKey() { Object cacheKey = CacheKeyFactory.createKey(String.class, Long.class); Object cacheKey2 = CacheKeyFactory.createKey(String.class, Long.class); assertEquals(cacheKey, cacheKey2); assertEquals(cacheKey.hashCode(), cacheKey2.hashCode()); }
@Test public void canCreateKeyInReverse() { Object cacheKey = CacheKeyFactory.createKey(String.class, Long.class); Object cacheKey2 = CacheKeyFactory.createKey(Long.class, String.class); assertNotEquals(cacheKey, cacheKey2); assertNotEquals(cacheKey2, cacheKey); assertNotEquals(cacheKey.hashCode(), cacheKey2.hashCode()); }
@Test public void canCreateKeyForAllParameters() { Object cacheKey = CacheKeyFactory.createKey(String.class, Long.class, "A"); Object cacheKey2 = CacheKeyFactory.createKey(String.class, Long.class, "B"); assertNotEquals(cacheKey, cacheKey2); assertNotEquals(cacheKey2, cacheKey); assertNotEquals(cacheKey.hashCode(), cacheKey2.hashCode()); }
@Test public void canCreateKeyAndHandlesNullGracefullyInEquals() { Object nullCacheKey = null; Object normalCacheKey = CacheKeyFactory.createKey(String.class, Long.class); assertNotEquals(normalCacheKey, nullCacheKey); }
@Test public void canCreateKeyEquivalenceOfSelf() { Object cacheKey = CacheKeyFactory.createKey(String.class, Long.class); assertEquals(cacheKey, cacheKey); }