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
.jcache
;
9 import java
.util
.function
.BiConsumer
;
10 import java
.util
.function
.BiFunction
;
11 import java
.util
.function
.BiPredicate
;
12 import java
.util
.function
.BooleanSupplier
;
13 import java
.util
.function
.Consumer
;
14 import java
.util
.function
.DoubleBinaryOperator
;
15 import java
.util
.function
.DoubleConsumer
;
16 import java
.util
.function
.DoubleFunction
;
17 import java
.util
.function
.DoublePredicate
;
18 import java
.util
.function
.DoubleSupplier
;
19 import java
.util
.function
.Function
;
20 import java
.util
.function
.IntBinaryOperator
;
21 import java
.util
.function
.IntConsumer
;
22 import java
.util
.function
.IntFunction
;
23 import java
.util
.function
.IntPredicate
;
24 import java
.util
.function
.IntSupplier
;
25 import java
.util
.function
.LongBinaryOperator
;
26 import java
.util
.function
.LongConsumer
;
27 import java
.util
.function
.LongFunction
;
28 import java
.util
.function
.LongPredicate
;
29 import java
.util
.function
.LongSupplier
;
30 import java
.util
.function
.ObjDoubleConsumer
;
31 import java
.util
.function
.ObjIntConsumer
;
32 import java
.util
.function
.Predicate
;
33 import java
.util
.function
.Supplier
;
35 import org
.junit
.Assert
;
36 import org
.junit
.Test
;
38 import de
.xn__ho_hia
.memoization
.shared
.DoubleBinaryFunction
;
39 import de
.xn__ho_hia
.memoization
.shared
.IntBinaryFunction
;
40 import de
.xn__ho_hia
.memoization
.shared
.LongBinaryFunction
;
41 import de
.xn__ho_hia
.memoization
.shared
.ObjDoubleFunction
;
42 import de
.xn__ho_hia
.memoization
.shared
.ObjIntFunction
;
43 import de
.xn__ho_hia
.quality
.suppression
.CompilerWarnings
;
48 @SuppressWarnings({ CompilerWarnings
.NLS
, CompilerWarnings
.STATIC_METHOD
})
49 public class JCacheMemoizeCustomKeyTest
{
55 public void shouldMemoizeBiConsumerWithKeyFunction() {
57 final BiConsumer
<String
, String
> consumer
= (a
, b
) -> System
.out
.println(a
+ b
);
58 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
61 final BiConsumer
<String
, String
> memoize
= JCacheMemoize
.biConsumer(consumer
, keyFunction
);
64 Assert
.assertNotNull("Memoized BiConsumer is NULL", memoize
);
71 public void shouldMemoizeBiFunctionWithKeyBiFunction() {
73 final BiFunction
<String
, String
, String
> function
= (first
, second
) -> "test";
74 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
77 final BiFunction
<String
, String
, String
> memoize
= JCacheMemoize
.biFunction(function
, keyFunction
);
80 Assert
.assertNotNull("Memoized BiFunction is NULL", memoize
);
87 public void shouldMemoizeBiPredicateWithKeyBiFunction() {
89 final BiPredicate
<String
, String
> biPredicate
= (first
, second
) -> true;
90 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
93 final BiPredicate
<String
, String
> memoize
= JCacheMemoize
.biPredicate(biPredicate
, keyFunction
);
96 Assert
.assertNotNull("Memoized BiPredicate is NULL", memoize
);
103 public void shouldMemoizeBooleanSupplierWithKeySupplier() {
105 final BooleanSupplier supplier
= () -> true;
106 final Supplier
<String
> keySupplier
= () -> "key";
109 final BooleanSupplier memoize
= JCacheMemoize
.booleanSupplier(supplier
, keySupplier
);
112 Assert
.assertNotNull("Memoized BooleanSupplier is NULL", memoize
);
119 public void shouldMemoizeConsumerWithKeyFunction() {
121 final Consumer
<String
> consumer
= System
.out
::println
;
122 final Function
<String
, String
> keyFunction
= Function
.identity();
125 final Consumer
<String
> memoize
= JCacheMemoize
.consumer(consumer
, keyFunction
);
128 Assert
.assertNotNull("Memoized Consumer is NULL", memoize
);
135 public void shouldMemoizeDoubleBinaryOperatorWithKeyFunction() {
137 final DoubleBinaryOperator operator
= (a
, b
) -> 123.456D
;
138 final DoubleBinaryFunction
<String
> keyFunction
= (a
, b
) -> "key";
141 final DoubleBinaryOperator memoize
= JCacheMemoize
.doubleBinaryOperator(operator
, keyFunction
);
144 Assert
.assertNotNull("Memoized DoubleBinaryOperator is NULL", memoize
);
151 public void shouldMemoizeDoubleConsumerWithKeyFunction() {
153 final DoubleConsumer consumer
= System
.out
::println
;
154 final DoubleFunction
<String
> keyFunction
= a
-> "key";
157 final DoubleConsumer memoize
= JCacheMemoize
.doubleConsumer(consumer
, keyFunction
);
160 Assert
.assertNotNull("Memoized DoubleConsumer is NULL", memoize
);
167 public void shouldMemoizeDoubleFunction() {
169 final DoubleFunction
<String
> function
= a
-> "test";
170 final DoubleFunction
<String
> keyFunction
= a
-> "key";
173 final DoubleFunction
<String
> memoize
= JCacheMemoize
.doubleFunction(function
, keyFunction
);
176 Assert
.assertNotNull("Memoized DoubleFunction is NULL", memoize
);
183 public void shouldMemoizeDoublePredicateWithKeyFunction() {
185 final DoublePredicate predicate
= a
-> true;
186 final DoubleFunction
<String
> keyFunction
= a
-> "key";
189 final DoublePredicate memoize
= JCacheMemoize
.doublePredicate(predicate
, keyFunction
);
192 Assert
.assertNotNull("Memoized DoublePredicate is NULL", memoize
);
199 public void shouldMemoizeDoubleSupplierWithKeyFunction() {
201 final DoubleSupplier supplier
= () -> 123.456D
;
202 final Supplier
<String
> keySupplier
= () -> "key";
205 final DoubleSupplier memoize
= JCacheMemoize
.doubleSupplier(supplier
, keySupplier
);
208 Assert
.assertNotNull("Memoized DoubleSupplier is NULL", memoize
);
215 public void shouldMemoizeFunctionWithKeyFunction() {
217 final Function
<String
, String
> function
= a
-> "test";
218 final Function
<String
, String
> keyFunction
= Function
.identity();
221 final Function
<String
, String
> memoize
= JCacheMemoize
.function(function
, keyFunction
);
224 Assert
.assertNotNull("Memoized Function is NULL", memoize
);
231 public void shouldMemoizeIntBinaryOperatorWithKeyFunction() {
233 final IntBinaryOperator operator
= (a
, b
) -> 123;
234 final IntBinaryFunction
<String
> keyFunction
= (a
, b
) -> "key";
237 final IntBinaryOperator memoize
= JCacheMemoize
.intBinaryOperator(operator
, keyFunction
);
240 Assert
.assertNotNull("Memoized IntBinaryOperator is NULL", memoize
);
247 public void shouldMemoizeIntConsumerWithKeyFunction() {
249 final IntConsumer consumer
= System
.out
::println
;
250 final IntFunction
<String
> keyFunction
= a
-> "key";
253 final IntConsumer memoize
= JCacheMemoize
.intConsumer(consumer
, keyFunction
);
256 Assert
.assertNotNull("Memoized IntConsumer is NULL", memoize
);
263 public void shouldMemoizeIntFunctionWithKeyFunction() {
265 final IntFunction
<String
> function
= a
-> "test";
266 final IntFunction
<String
> keyFunction
= a
-> "key";
269 final IntFunction
<String
> memoize
= JCacheMemoize
.intFunction(function
, keyFunction
);
272 Assert
.assertNotNull("Memoized IntFunction is NULL", memoize
);
279 public void shouldMemoizeIntPredicateWithKeyFunction() {
281 final IntPredicate predicate
= a
-> true;
282 final IntFunction
<String
> keyFunction
= a
-> "key";
285 final IntPredicate memoize
= JCacheMemoize
.intPredicate(predicate
, keyFunction
);
288 Assert
.assertNotNull("Memoized IntPredicate is NULL", memoize
);
295 public void shouldMemoizeIntSupplierWithKeyFunction() {
297 final IntSupplier supplier
= () -> 123;
298 final Supplier
<String
> keySupplier
= () -> "key";
301 final IntSupplier memoize
= JCacheMemoize
.intSupplier(supplier
, keySupplier
);
304 Assert
.assertNotNull("Memoized IntSupplier is NULL", memoize
);
311 public void shouldMemoizeLongBinaryOperatorWithKeyFunction() {
313 final LongBinaryOperator operator
= (a
, b
) -> 123L;
314 final LongBinaryFunction
<String
> keyFunction
= (a
, b
) -> "key";
317 final LongBinaryOperator memoize
= JCacheMemoize
.longBinaryOperator(operator
, keyFunction
);
320 Assert
.assertNotNull("Memoized LongBinaryOperator is NULL", memoize
);
327 public void shouldMemoizeLongConsumer() {
329 final LongConsumer consumer
= System
.out
::println
;
330 final LongFunction
<String
> keyFunction
= a
-> "key";
333 final LongConsumer memoize
= JCacheMemoize
.longConsumer(consumer
, keyFunction
);
336 Assert
.assertNotNull("Memoized LongConsumer is NULL", memoize
);
343 public void shouldMemoizeLongFunctionWithKeyFunction() {
345 final LongFunction
<String
> function
= a
-> "test";
346 final LongFunction
<String
> keyFunction
= a
-> "key";
349 final LongFunction
<String
> memoize
= JCacheMemoize
.longFunction(function
, keyFunction
);
352 Assert
.assertNotNull("Memoized LongFunction is NULL", memoize
);
359 public void shouldMemoizeLongPredicateWithKeyFunction() {
361 final LongPredicate predicate
= a
-> true;
362 final LongFunction
<String
> keyFunction
= a
-> "key";
365 final LongPredicate memoize
= JCacheMemoize
.longPredicate(predicate
, keyFunction
);
368 Assert
.assertNotNull("Memoized LongPredicate is NULL", memoize
);
375 public void shouldMemoizeLongSupplierWithKeyFunction() {
377 final LongSupplier supplier
= () -> 123L;
378 final Supplier
<String
> keySupplier
= () -> "key";
381 final LongSupplier memoize
= JCacheMemoize
.longSupplier(supplier
, keySupplier
);
384 Assert
.assertNotNull("Memoized LongSupplier is NULL", memoize
);
391 public void shouldMemoizeObjDoubleConsumerWithKeyFunction() {
393 final ObjDoubleConsumer
<String
> consumer
= (a
, b
) -> System
.out
.println(a
+ b
);
394 final ObjDoubleFunction
<String
, String
> keyFunction
= (a
, b
) -> "key";
397 final ObjDoubleConsumer
<String
> memoize
= JCacheMemoize
.objDoubleConsumer(consumer
, keyFunction
);
400 Assert
.assertNotNull("Memoized ObjDoubleConsumer is NULL", memoize
);
407 public void shouldMemoizeObjIntConsumerWithKeyFunction() {
409 final ObjIntConsumer
<String
> consumer
= (a
, b
) -> System
.out
.println(a
+ b
);
410 final ObjIntFunction
<String
, String
> keyFunction
= (a
, b
) -> "key";
413 final ObjIntConsumer
<String
> memoize
= JCacheMemoize
.objIntConsumer(consumer
, keyFunction
);
416 Assert
.assertNotNull("Memoized ObjIntConsumer is NULL", memoize
);
423 public void shouldMemoizePredicateWithKeyFunction() {
425 final Predicate
<String
> predicate
= a
-> true;
426 final Function
<String
, String
> keyFunction
= Function
.identity();
429 final Predicate
<String
> memoize
= JCacheMemoize
.predicate(predicate
, keyFunction
);
432 Assert
.assertNotNull("Memoized Predicate is NULL", memoize
);
439 public void shouldMemoizeSupplierWithKeySupplier() {
441 final Supplier
<String
> supplier
= () -> "test";
442 final Supplier
<String
> keySupplier
= () -> "key";
445 final Supplier
<String
> memoize
= JCacheMemoize
.supplier(supplier
, keySupplier
);
448 Assert
.assertNotNull("Memoized Supplier is NULL", memoize
);