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
;
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
;
25 @SuppressWarnings({ CompilerWarnings
.NLS
, CompilerWarnings
.STATIC_METHOD
})
26 public class GuavaCacheBasedBiFunctionMemoizerTest
{
28 /** Captures expected exceptions. */
30 public ExpectedException thrown
= ExpectedException
.none();
36 public void shouldAcceptCacheAndKeyFunctionAndBiFunction() {
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();
43 final GuavaCacheBasedBiFunctionMemoizer
<String
, String
, String
, String
> memoizer
= new GuavaCacheBasedBiFunctionMemoizer
<>(
44 cache
, keyFunction
, biFunction
);
47 Assert
.assertNotNull(memoizer
);
54 public void shouldTransformInput() {
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();
61 final GuavaCacheBasedBiFunctionMemoizer
<String
, String
, String
, String
> memoizer
= new GuavaCacheBasedBiFunctionMemoizer
<>(
62 cache
, keyFunction
, biFunction
);
65 Assert
.assertEquals("firstsecond", memoizer
.apply("first", "second"));