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
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
;
26 @SuppressWarnings({ CompilerWarnings
.NLS
, CompilerWarnings
.STATIC_METHOD
})
27 public class GuavaCacheBasedBiPredicateMemoizerTest
{
29 /** Captures expected exceptions. */
31 public ExpectedException thrown
= ExpectedException
.none();
37 public void shouldAcceptCacheAndKeyFunctionAndBiPredicate() {
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();
44 final GuavaCacheBasedBiPredicateMemoizer
<String
, String
, String
> memoizer
= new GuavaCacheBasedBiPredicateMemoizer
<>(
45 cache
, keyFunction
, biFunction
);
48 Assert
.assertNotNull(memoizer
);
55 public void shouldTransformInput() {
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();
62 final GuavaCacheBasedBiPredicateMemoizer
<String
, String
, String
> memoizer
= new GuavaCacheBasedBiPredicateMemoizer
<>(
63 cache
, keyFunction
, biFunction
);
66 Assert
.assertTrue(memoizer
.test("first", "second"));