@Test public void spr11592GetNeverCache() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class); Spr11592Service bean = context.getBean(Spr11592Service.class); Cache cache = context.getBean("cache", Cache.class); String key = "1"; Object result = bean.getNeverCache("1"); verify(cache, times(0)).get(key); // no cache hit at all, caching disabled Object cachedResult = bean.getNeverCache("1"); assertNotSame(result, cachedResult); verify(cache, times(0)).get(key); // caching disabled context.close(); }
@Test public void spr11592GetSimple() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class); Spr11592Service bean = context.getBean(Spr11592Service.class); Cache cache = context.getBean("cache", Cache.class); String key = "1"; Object result = bean.getSimple("1"); verify(cache, times(1)).get(key); // first call: cache miss Object cachedResult = bean.getSimple("1"); assertSame(result, cachedResult); verify(cache, times(2)).get(key); // second call: cache hit context.close(); }