UpdateMultiCacheAdvice extends MultiCacheAdvice { void updateCache(final List<String> cacheKeys, final List<Object> returnList, final Method methodToCache, final AnnotationData data, final SerializationType serializationType) { if (returnList.size() != cacheKeys.size()) { throw new InvalidAnnotationException(String.format( "The key generation objects, and the resulting objects do not match in size for [%s].", methodToCache.toString())); } Iterator<Object> returnListIter = returnList.iterator(); Iterator<String> cacheKeyIter = cacheKeys.iterator(); String cacheKey; Object result, cacheObject; while (returnListIter.hasNext()) { result = returnListIter.next(); cacheKey = cacheKeyIter.next(); cacheObject = getCacheBase().getSubmission(result); getCacheBase().getCache(data).setSilently(cacheKey, data.getExpiration(), cacheObject, serializationType); } }  @Pointcut("@annotation(com.google.code.ssm.api.UpdateMultiCache)") void updateMulti(); @AfterReturning(pointcut = "updateMulti()", returning = "retVal") void cacheUpdateMulti(final JoinPoint jp, final Object retVal);  }
@Test public void testUpdateCache() throws Exception { final Method method = AnnotationTest.class.getMethod("cacheMe01", List.class); final UpdateMultiCache annotation = method.getAnnotation(UpdateMultiCache.class); final AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, UpdateMultiCache.class, method); final List<String> keys = new ArrayList<String>(); final List<Object> objs = new ArrayList<Object>(); keys.add("Key1-" + System.currentTimeMillis()); keys.add("Key2-" + System.currentTimeMillis()); try { cut.updateCache(keys, objs, method, data, null); fail("Expected Exception."); } catch (InvalidAnnotationException ex) { assertTrue(ex.getMessage().contains("do not match in size")); } final Cache cache = EasyMock.createMock(Cache.class); EasyMock.expect(cache.getName()).andReturn(AnnotationConstants.DEFAULT_CACHE_NAME); EasyMock.expect(cache.getAliases()).andReturn(Collections.<String> emptyList()).anyTimes(); EasyMock.expect(cache.getProperties()).andReturn(new CacheProperties()).anyTimes(); for (final String key : keys) { final String value = "ValueFor-" + key; objs.add(value); cache.setSilently(key, data.getExpiration(), value, null); EasyMock.expectLastCall(); } keys.add("BigFatNull"); objs.add(null); cache.setSilently(keys.get(2), data.getExpiration(), new PertinentNegativeNull(), null); EasyMock.expectLastCall(); EasyMock.replay(cache); cut.getCacheBase().addCache(cache); cut.updateCache(keys, objs, method, data, null); EasyMock.verify(cache); }