IncrementCounterInCacheAdvice extends CounterInCacheBase { @AfterReturning("incrementSingleCounter()") public void incrementSingle(final JoinPoint jp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return; } String cacheKey = null; IncrementCounterInCache annotation; try { Method methodToCache = getCacheBase().getMethodToCache(jp, IncrementCounterInCache.class); annotation = methodToCache.getAnnotation(IncrementCounterInCache.class); AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, IncrementCounterInCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString()); getCacheBase().getCache(data).incr(cacheKey, 1, 1); } catch (Exception ex) { warn(ex, "Incrementing counter [%s] via %s aborted due to an error.", cacheKey, jp.toShortString()); } }  @Pointcut("@annotation(com.google.code.ssm.api.counter.IncrementCounterInCache)") void incrementSingleCounter(); @AfterReturning("incrementSingleCounter()") void incrementSingle(final JoinPoint jp);  }
@Test public void validIncrementCounterInCache() throws Throwable { Assume.assumeTrue(isValid); advice.incrementSingle(pjp); verify(cache).incr(cacheKey, 1, 1L); }
@Test public void invalidIncrementCounterInCache() throws Throwable { Assume.assumeThat(isValid, CoreMatchers.is(false)); advice.incrementSingle(pjp); verify(cache, never()).incr(cacheKey, 1, 1L); }