TranslatorCachingWrapper implements Translator { @Override public String translate(String key) { String value = cache.get(key); if (value == null) { value = wrappedTranslator.translate(key); cache.putIfAbsent(key, value); } return value; } TranslatorCachingWrapper(Translator wrappedTranslator); @Override String translate(String key);  }
@Test public void testCacheMiss() { String value = cachingWrapper.translate("testKey"); assertEquals("testValue", value); verify(mockTranslator, times(1)).translate("testKey"); }
@Test public void testCacheHit() { String value = cachingWrapper.translate("testKey"); value = cachingWrapper.translate("testKey"); assertEquals("testValue", value); verify(mockTranslator, times(1)).translate("testKey"); }