CachingConverter implements IConverter<C> { @Override public C convertToObject(String value, Locale locale) throws ConversionException { try { return toObjectCache.get(new Key<>(value, locale)); } catch (ExecutionException ex) { throw new ConversionException(ex); } } CachingConverter(IConverter<C> converter); static IConverter<C> wrap(IConverter<C> inner); @Override C convertToObject(String value, Locale locale); @Override String convertToString(C value, Locale locale);  }
@Test public void testConvertToObject() { final IConverter<Object> inner = context.mock(IConverter.class, "Object"); final CachingConverter instance = new CachingConverter<>(inner); final Object result = new Object(); context.checking(new Expectations() { { oneOf(inner).convertToObject("value", Locale.CANADA_FRENCH); will(returnValue(result)); } }); Object actual = instance.convertToObject("value", Locale.CANADA_FRENCH); assertSame(result, actual); actual = instance.convertToObject("value", Locale.CANADA_FRENCH); assertSame(result, actual); actual = instance.convertToObject("value", Locale.CANADA_FRENCH); assertSame(result, actual); context.checking(new Expectations() { { oneOf(inner).convertToObject("value", Locale.FRENCH); will(returnValue(result)); oneOf(inner).convertToObject("otherValue", Locale.FRENCH); will(returnValue(result)); } }); actual = instance.convertToObject("value", Locale.FRENCH); assertSame(result, actual); actual = instance.convertToObject("otherValue", Locale.FRENCH); assertSame(result, actual); }