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
.DoubleConsumer
;
15 import java
.util
.function
.DoubleFunction
;
16 import java
.util
.function
.DoublePredicate
;
17 import java
.util
.function
.DoubleSupplier
;
18 import java
.util
.function
.Function
;
19 import java
.util
.function
.IntConsumer
;
20 import java
.util
.function
.IntFunction
;
21 import java
.util
.function
.IntPredicate
;
22 import java
.util
.function
.IntSupplier
;
23 import java
.util
.function
.LongConsumer
;
24 import java
.util
.function
.LongFunction
;
25 import java
.util
.function
.LongPredicate
;
26 import java
.util
.function
.LongSupplier
;
27 import java
.util
.function
.Predicate
;
28 import java
.util
.function
.Supplier
;
30 import org
.junit
.Assert
;
31 import org
.junit
.Test
;
33 import de
.xn__ho_hia
.quality
.suppression
.CompilerWarnings
;
38 @SuppressWarnings({ CompilerWarnings
.NLS
, CompilerWarnings
.STATIC_METHOD
})
39 public class JCacheMemoizeCustomKeyTest
{
45 public void shouldMemoizeSupplierWithKeySupplier() {
47 final Supplier
<String
> supplier
= () -> "test";
48 final Supplier
<String
> keySupplier
= () -> "key";
51 final Supplier
<String
> memoize
= JCacheMemoize
.supplier(supplier
, keySupplier
);
54 Assert
.assertNotNull("Memoized Supplier is NULL", memoize
);
61 public void shouldMemoizeBooleanSupplierWithKeySupplier() {
63 final BooleanSupplier supplier
= () -> true;
64 final Supplier
<String
> keySupplier
= () -> "key";
67 final BooleanSupplier memoize
= JCacheMemoize
.booleanSupplier(supplier
, keySupplier
);
70 Assert
.assertNotNull("Memoized BooleanSupplier is NULL", memoize
);
77 public void shouldMemoizeDoubleSupplierWithKeyFunction() {
79 final DoubleSupplier supplier
= () -> 123.456D
;
80 final Supplier
<String
> keySupplier
= () -> "key";
83 final DoubleSupplier memoize
= JCacheMemoize
.doubleSupplier(supplier
, keySupplier
);
86 Assert
.assertNotNull("Memoized DoubleSupplier is NULL", memoize
);
93 public void shouldMemoizeIntSupplierWithKeyFunction() {
95 final IntSupplier supplier
= () -> 123;
96 final Supplier
<String
> keySupplier
= () -> "key";
99 final IntSupplier memoize
= JCacheMemoize
.intSupplier(supplier
, keySupplier
);
102 Assert
.assertNotNull("Memoized IntSupplier is NULL", memoize
);
109 public void shouldMemoizeLongSupplierWithKeyFunction() {
111 final LongSupplier supplier
= () -> 123L;
112 final Supplier
<String
> keySupplier
= () -> "key";
115 final LongSupplier memoize
= JCacheMemoize
.longSupplier(supplier
, keySupplier
);
118 Assert
.assertNotNull("Memoized LongSupplier is NULL", memoize
);
125 public void shouldMemoizeFunctionWithKeyFunction() {
127 final Function
<String
, String
> function
= a
-> "test";
128 final Function
<String
, String
> keyFunction
= Function
.identity();
131 final Function
<String
, String
> memoize
= JCacheMemoize
.function(function
, keyFunction
);
134 Assert
.assertNotNull("Memoized Function is NULL", memoize
);
141 public void shouldMemoizeIntFunctionWithKeyFunction() {
143 final IntFunction
<String
> function
= a
-> "test";
144 final IntFunction
<String
> keyFunction
= a
-> "key";
147 final IntFunction
<String
> memoize
= JCacheMemoize
.intFunction(function
, keyFunction
);
150 Assert
.assertNotNull("Memoized IntFunction is NULL", memoize
);
157 public void shouldMemoizeLongFunctionWithKeyFunction() {
159 final LongFunction
<String
> function
= a
-> "test";
160 final LongFunction
<String
> keyFunction
= a
-> "key";
163 final LongFunction
<String
> memoize
= JCacheMemoize
.longFunction(function
, keyFunction
);
166 Assert
.assertNotNull("Memoized LongFunction is NULL", memoize
);
173 public void shouldMemoizeDoubleFunction() {
175 final DoubleFunction
<String
> function
= a
-> "test";
176 final DoubleFunction
<String
> keyFunction
= a
-> "key";
179 final DoubleFunction
<String
> memoize
= JCacheMemoize
.doubleFunction(function
, keyFunction
);
182 Assert
.assertNotNull("Memoized DoubleFunction is NULL", memoize
);
189 public void shouldMemoizePredicateWithKeyFunction() {
191 final Predicate
<String
> predicate
= a
-> true;
192 final Function
<String
, String
> keyFunction
= Function
.identity();
195 final Predicate
<String
> memoize
= JCacheMemoize
.predicate(predicate
, keyFunction
);
198 Assert
.assertNotNull("Memoized Predicate is NULL", memoize
);
205 public void shouldMemoizeDoublePredicateWithKeyFunction() {
207 final DoublePredicate predicate
= a
-> true;
208 final DoubleFunction
<String
> keyFunction
= a
-> "key";
211 final DoublePredicate memoize
= JCacheMemoize
.doublePredicate(predicate
, keyFunction
);
214 Assert
.assertNotNull("Memoized DoublePredicate is NULL", memoize
);
221 public void shouldMemoizeIntPredicateWithKeyFunction() {
223 final IntPredicate predicate
= a
-> true;
224 final IntFunction
<String
> keyFunction
= a
-> "key";
227 final IntPredicate memoize
= JCacheMemoize
.intPredicate(predicate
, keyFunction
);
230 Assert
.assertNotNull("Memoized IntPredicate is NULL", memoize
);
237 public void shouldMemoizeLongPredicateWithKeyFunction() {
239 final LongPredicate predicate
= a
-> true;
240 final LongFunction
<String
> keyFunction
= a
-> "key";
243 final LongPredicate memoize
= JCacheMemoize
.longPredicate(predicate
, keyFunction
);
246 Assert
.assertNotNull("Memoized LongPredicate is NULL", memoize
);
253 public void shouldMemoizeConsumerWithKeyFunction() {
255 final Consumer
<String
> consumer
= System
.out
::println
;
256 final Function
<String
, String
> keyFunction
= Function
.identity();
259 final Consumer
<String
> memoize
= JCacheMemoize
.consumer(consumer
, keyFunction
);
262 Assert
.assertNotNull("Memoized Consumer is NULL", memoize
);
269 public void shouldMemoizeDoubleConsumerWithKeyFunction() {
271 final DoubleConsumer consumer
= System
.out
::println
;
272 final DoubleFunction
<String
> keyFunction
= a
-> "key";
275 final DoubleConsumer memoize
= JCacheMemoize
.doubleConsumer(consumer
, keyFunction
);
278 Assert
.assertNotNull("Memoized DoubleConsumer is NULL", memoize
);
285 public void shouldMemoizeIntConsumerWithKeyFunction() {
287 final IntConsumer consumer
= System
.out
::println
;
288 final IntFunction
<String
> keyFunction
= a
-> "key";
291 final IntConsumer memoize
= JCacheMemoize
.intConsumer(consumer
, keyFunction
);
294 Assert
.assertNotNull("Memoized IntConsumer is NULL", memoize
);
301 public void shouldMemoizeLongConsumer() {
303 final LongConsumer consumer
= System
.out
::println
;
304 final LongFunction
<String
> keyFunction
= a
-> "key";
307 final LongConsumer memoize
= JCacheMemoize
.longConsumer(consumer
, keyFunction
);
310 Assert
.assertNotNull("Memoized LongConsumer is NULL", memoize
);
317 public void shouldMemoizeBiConsumerWithKeyFunction() {
319 final BiConsumer
<String
, String
> consumer
= (a
, b
) -> System
.out
.println(a
+ b
);
320 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
323 final BiConsumer
<String
, String
> memoize
= JCacheMemoize
.biConsumer(consumer
, keyFunction
);
326 Assert
.assertNotNull("Memoized BiConsumer is NULL", memoize
);
333 public void shouldMemoizeBiFunctionWithKeyBiFunction() {
335 final BiFunction
<String
, String
, String
> function
= (first
, second
) -> "test";
336 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
339 final BiFunction
<String
, String
, String
> memoize
= JCacheMemoize
.biFunction(function
, keyFunction
);
342 Assert
.assertNotNull("Memoized BiFunction is NULL", memoize
);
349 public void shouldMemoizeBiPredicateWithKeyBiFunction() {
351 final BiPredicate
<String
, String
> biPredicate
= (first
, second
) -> true;
352 final BiFunction
<String
, String
, String
> keyFunction
= (first
, second
) -> "key";
355 final BiPredicate
<String
, String
> memoize
= JCacheMemoize
.biPredicate(biPredicate
, keyFunction
);
358 Assert
.assertNotNull("Memoized BiPredicate is NULL", memoize
);