JCacheBasedObjIntConsumerMemoizer extends AbstractJCacheBasedMemoizer<KEY, KEY> implements ObjIntConsumer<FIRST> { @Override public void accept(final FIRST first, final int value) { final KEY key = keyFunction.apply(first, value); invoke(key, givenKey -> { biConsumer.accept(first, value); return givenKey; }); } JCacheBasedObjIntConsumerMemoizer(
            final Cache<KEY, KEY> cache,
            final ObjIntFunction<FIRST, KEY> keyFunction,
            final ObjIntConsumer<FIRST> biConsumer); @Override void accept(final FIRST first, final int value);  }
@Test @SuppressWarnings(CompilerWarnings.UNCHECKED) public void shouldAcceptInput() { final ObjIntConsumer<String> biConsumer = Mockito.mock(ObjIntConsumer.class); final ObjIntFunction<String, String> keyfunction = (a, b) -> "key"; try (final Cache<String, String> cache = JCacheMemoize.createCache(BiConsumer.class)) { final JCacheBasedObjIntConsumerMemoizer<String, String> memoizer = new JCacheBasedObjIntConsumerMemoizer<>( cache, keyfunction, biConsumer); memoizer.accept("first", 123); Mockito.verify(biConsumer).accept("first", 123); } }
@Test @SuppressWarnings(CompilerWarnings.UNCHECKED) public void shouldWrapRuntimeExceptionInMemoizationException() { final ObjIntFunction<String, String> keyfunction = (a, b) -> "key"; try (final Cache<String, String> cache = Mockito.mock(Cache.class)) { final JCacheBasedObjIntConsumerMemoizer<String, String> loader = new JCacheBasedObjIntConsumerMemoizer<>( cache, keyfunction, null); given(cache.invoke(any(), any())).willThrow(RuntimeException.class); thrown.expect(MemoizationException.class); loader.accept("first", 123); } }