2 * SPDX-FileCopyrightText: The memoization.java Authors
3 * SPDX-License-Identifier: 0BSD
5 package wtf
.metio
.memoization
.guava
;
7 import com
.google
.common
.cache
.Cache
;
8 import com
.google
.common
.cache
.CacheBuilder
;
9 import org
.junit
.jupiter
.api
.Assertions
;
10 import org
.junit
.jupiter
.api
.Test
;
12 import java
.util
.function
.BiFunction
;
14 class GuavaCacheBasedBiFunctionMemoizerTest
{
17 void shouldAcceptCacheAndKeyFunctionAndBiFunction() {
19 final BiFunction
<String
, String
, String
> biFunction
= (first
, second
) -> first
+ second
;
20 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> second
+ first
;
21 final Cache
<String
, String
> cache
= CacheBuilder
.newBuilder().build();
24 final var memoizer
= new GuavaCacheBasedBiFunctionMemoizer
<>(cache
, keyFunction
, biFunction
);
27 Assertions
.assertNotNull(memoizer
);
31 void shouldTransformInput() {
33 final BiFunction
<String
, String
, String
> biFunction
= (first
, second
) -> first
+ second
;
34 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> second
+ first
;
35 final Cache
<String
, String
> cache
= CacheBuilder
.newBuilder().build();
38 final var memoizer
= new GuavaCacheBasedBiFunctionMemoizer
<>(cache
, keyFunction
, biFunction
);
41 Assertions
.assertEquals("firstsecond", memoizer
.apply("first", "second"));