fix #68
[memoization.java.git] / memoization-guava / src / test / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedBiFunctionMemoizerTest.java
blob94d1847184d93f514ce6267ef4dda40a5090f15f
1 /*
2 * This file is part of memoization.java. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of memoization.java,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
7 package de.xn__ho_hia.memoization.guava;
9 import java.util.function.BiFunction;
11 import com.google.common.cache.Cache;
12 import com.google.common.cache.CacheBuilder;
14 import org.junit.Assert;
15 import org.junit.Rule;
16 import org.junit.Test;
17 import org.junit.rules.ExpectedException;
19 import de.xn__ho_hia.quality.suppression.CompilerWarnings;
21 /**
25 @SuppressWarnings({ CompilerWarnings.NLS, CompilerWarnings.STATIC_METHOD })
26 public class GuavaCacheBasedBiFunctionMemoizerTest {
28 /** Captures expected exceptions. */
29 @Rule
30 public ExpectedException thrown = ExpectedException.none();
32 /**
35 @Test
36 public void shouldAcceptCacheAndKeyFunctionAndBiFunction() {
37 // given
38 final BiFunction<String, String, String> biFunction = (first, second) -> first + second;
39 final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
40 final Cache<String, String> cache = CacheBuilder.newBuilder().build();
42 // when
43 final GuavaCacheBasedBiFunctionMemoizer<String, String, String, String> memoizer = new GuavaCacheBasedBiFunctionMemoizer<>(
44 cache, keyFunction, biFunction);
46 // then
47 Assert.assertNotNull(memoizer);
50 /**
53 @Test
54 public void shouldTransformInput() {
55 // given
56 final BiFunction<String, String, String> biFunction = (first, second) -> first + second;
57 final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
58 final Cache<String, String> cache = CacheBuilder.newBuilder().build();
60 // when
61 final GuavaCacheBasedBiFunctionMemoizer<String, String, String, String> memoizer = new GuavaCacheBasedBiFunctionMemoizer<>(
62 cache, keyFunction, biFunction);
64 // then
65 Assert.assertEquals("firstsecond", memoizer.apply("first", "second"));