UpdatedCacheManager { public Collection<String> getOutDatedCache(Map<String, Long> map) { Collection<String> result = new ArrayList<>(); if (null != map) { for (Map.Entry<String, Long> entry : map.entrySet()) { String key = entry.getKey(); if (lastupdateTime.containsKey(key)) { if (lastupdateTime.get(key).compareTo(entry.getValue()) == 1) { logger.debug("Cache {} is outdated", key); result.add(key); } } } } return result; }  void receiveCacheRemoveEvent(@Observes @CacheEvent String cachekey); Collection<String> getOutDatedCache(Map<String, Long> map);  }
@Test public void testGetOutDatedCache() { System.out.println("getOutDatedCache"); String cachekey = UUID.randomUUID().toString(); Map<String, Long> map = new HashMap<>(); Date now = new Date(); map.put(cachekey, now.getTime()-DELAY); updatedCacheManager.receiveCacheRemoveEvent(cachekey); Collection<String> result = updatedCacheManager.getOutDatedCache(map); assertThat(result).isNotNull(); assertThat(result).contains(cachekey); }
@Test public void testGetNoOutDatedCache() { System.out.println("getNoOutDatedCache"); Map<String, Long> map = new HashMap<>(); Date now = new Date(); String cachekey = UUID.randomUUID().toString(); map.put(cachekey, now.getTime()-DELAY); Collection<String> result = updatedCacheManager.getOutDatedCache(map); assertThat(result).isNotNull(); assertThat(result).isEmpty(); }
@Test public void testGetOutDatedCacheNullMap() { System.out.println("getNoOutDatedCacheNullMap"); Collection<String> result = updatedCacheManager.getOutDatedCache(null); assertThat(result).isNotNull(); assertThat(result).isEmpty(); }