ReadThroughAssignCacheAdvice extends SingleReadCacheAdvice<ReadThroughAssignCache> { @Around("getSingleAssign()") public Object cacheSingleAssign(final ProceedingJoinPoint pjp) throws Throwable { return cache(pjp); } ReadThroughAssignCacheAdvice(); @Pointcut("@annotation(com.google.code.ssm.api.ReadThroughAssignCache)") void getSingleAssign(); @Around("getSingleAssign()") Object cacheSingleAssign(final ProceedingJoinPoint pjp);  }
@Test public void validCacheMiss() throws Throwable { Assume.assumeTrue(isValid); when(pjp.proceed()).thenReturn(expectedValue); assertEquals(expectedValue, advice.cacheSingleAssign(pjp)); verify(cache).get(eq(cacheKey), any(SerializationType.class)); verify(cache).set(eq(cacheKey), eq(EXPIRATION), eq(expectedValue), any(SerializationType.class)); verify(pjp).proceed(); }
@Test public void validCacheHit() throws Throwable { Assume.assumeTrue(isValid); when(cache.get(eq(cacheKey), any(SerializationType.class))).thenReturn(expectedValue); assertEquals(expectedValue, advice.cacheSingleAssign(pjp)); verify(cache).get(eq(cacheKey), any(SerializationType.class)); verify(cache, never()).set(anyString(), anyInt(), any(), any(SerializationType.class)); verify(pjp, never()).proceed(); }
@Test public void invalid() throws Throwable { Assume.assumeThat(isValid, CoreMatchers.is(false)); when(pjp.proceed()).thenReturn(expectedValue); assertEquals(expectedValue, advice.cacheSingleAssign(pjp)); verify(cache, never()).get(anyString(), any(SerializationType.class)); verify(cache, never()).set(anyString(), anyInt(), any(), any(SerializationType.class)); verify(pjp).proceed(); }