reformat & fix javadocs
[memoization.java.git] / memoization-guava / src / test / java / wtf / metio / memoization / guava / GuavaCacheBasedBiFunctionMemoizerTest.java
blob74fefbb6c6ae5997afe0cffba5e6dc1814f2c786
1 /*
2 * SPDX-FileCopyrightText: The memoization.java Authors
3 * SPDX-License-Identifier: 0BSD
4 */
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 {
16 @Test
17 void shouldAcceptCacheAndKeyFunctionAndBiFunction() {
18 // given
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();
23 // when
24 final var memoizer = new GuavaCacheBasedBiFunctionMemoizer<>(cache, keyFunction, biFunction);
26 // then
27 Assertions.assertNotNull(memoizer);
30 @Test
31 void shouldTransformInput() {
32 // given
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();
37 // when
38 final var memoizer = new GuavaCacheBasedBiFunctionMemoizer<>(cache, keyFunction, biFunction);
40 // then
41 Assertions.assertEquals("firstsecond", memoizer.apply("first", "second"));