fix #68
[memoization.java.git] / memoization-guava / src / test / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedBiPredicateMemoizerTest.java
blob7a0f936f87c577e73e6f7cefb6447f5f2db4ff0d
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;
10 import java.util.function.BiPredicate;
12 import com.google.common.cache.Cache;
13 import com.google.common.cache.CacheBuilder;
15 import org.junit.Assert;
16 import org.junit.Rule;
17 import org.junit.Test;
18 import org.junit.rules.ExpectedException;
20 import de.xn__ho_hia.quality.suppression.CompilerWarnings;
22 /**
26 @SuppressWarnings({ CompilerWarnings.NLS, CompilerWarnings.STATIC_METHOD })
27 public class GuavaCacheBasedBiPredicateMemoizerTest {
29 /** Captures expected exceptions. */
30 @Rule
31 public ExpectedException thrown = ExpectedException.none();
33 /**
36 @Test
37 public void shouldAcceptCacheAndKeyFunctionAndBiPredicate() {
38 // given
39 final BiPredicate<String, String> biFunction = (first, second) -> true;
40 final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
41 final Cache<String, Boolean> cache = CacheBuilder.newBuilder().build();
43 // when
44 final GuavaCacheBasedBiPredicateMemoizer<String, String, String> memoizer = new GuavaCacheBasedBiPredicateMemoizer<>(
45 cache, keyFunction, biFunction);
47 // then
48 Assert.assertNotNull(memoizer);
51 /**
54 @Test
55 public void shouldTransformInput() {
56 // given
57 final BiPredicate<String, String> biFunction = (first, second) -> true;
58 final BiFunction<String, String, String> keyFunction = (first, second) -> second + first;
59 final Cache<String, Boolean> cache = CacheBuilder.newBuilder().build();
61 // when
62 final GuavaCacheBasedBiPredicateMemoizer<String, String, String> memoizer = new GuavaCacheBasedBiPredicateMemoizer<>(
63 cache, keyFunction, biFunction);
65 // then
66 Assert.assertTrue(memoizer.test("first", "second"));