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 JCacheMemoizeDefaultsTest
{
45 public void shouldMemoizeSupplier() {
47 final Supplier
<String
> supplier
= () -> "test";
50 final Supplier
<String
> memoize
= JCacheMemoize
.supplier(supplier
);
53 Assert
.assertNotNull("Memoized Supplier is NULL", memoize
);
60 public void shouldMemoizeBooleanSupplier() {
62 final BooleanSupplier supplier
= () -> true;
65 final BooleanSupplier memoize
= JCacheMemoize
.booleanSupplier(supplier
);
68 Assert
.assertNotNull("Memoized BooleanSupplier is NULL", memoize
);
75 public void shouldMemoizeDoubleSupplier() {
77 final DoubleSupplier supplier
= () -> 123.456D
;
80 final DoubleSupplier memoize
= JCacheMemoize
.doubleSupplier(supplier
);
83 Assert
.assertNotNull("Memoized DoubleSupplier is NULL", memoize
);
90 public void shouldMemoizeIntSupplier() {
92 final IntSupplier supplier
= () -> 123;
95 final IntSupplier memoize
= JCacheMemoize
.intSupplier(supplier
);
98 Assert
.assertNotNull("Memoized IntSupplier is NULL", memoize
);
105 public void shouldMemoizeLongSupplier() {
107 final LongSupplier supplier
= () -> 123L;
110 final LongSupplier memoize
= JCacheMemoize
.longSupplier(supplier
);
113 Assert
.assertNotNull("Memoized LongSupplier is NULL", memoize
);
120 public void shouldMemoizeFunction() {
122 final Function
<String
, String
> function
= a
-> "test";
125 final Function
<String
, String
> memoize
= JCacheMemoize
.function(function
);
128 Assert
.assertNotNull("Memoized Function is NULL", memoize
);
135 public void shouldMemoizeIntFunction() {
137 final IntFunction
<String
> function
= a
-> "test";
140 final IntFunction
<String
> memoize
= JCacheMemoize
.intFunction(function
);
143 Assert
.assertNotNull("Memoized IntFunction is NULL", memoize
);
150 public void shouldMemoizeLongFunction() {
152 final LongFunction
<String
> function
= a
-> "test";
155 final LongFunction
<String
> memoize
= JCacheMemoize
.longFunction(function
);
158 Assert
.assertNotNull("Memoized LongFunction is NULL", memoize
);
165 public void shouldMemoizeDoubleFunction() {
167 final DoubleFunction
<String
> function
= a
-> "test";
170 final DoubleFunction
<String
> memoize
= JCacheMemoize
.doubleFunction(function
);
173 Assert
.assertNotNull("Memoized DoubleFunction is NULL", memoize
);
180 public void shouldMemoizePredicate() {
182 final Predicate
<String
> predicate
= a
-> true;
185 final Predicate
<String
> memoize
= JCacheMemoize
.predicate(predicate
);
188 Assert
.assertNotNull("Memoized Predicate is NULL", memoize
);
195 public void shouldMemoizeDoublePredicate() {
197 final DoublePredicate predicate
= a
-> true;
200 final DoublePredicate memoize
= JCacheMemoize
.doublePredicate(predicate
);
203 Assert
.assertNotNull("Memoized DoublePredicate is NULL", memoize
);
210 public void shouldMemoizeIntPredicate() {
212 final IntPredicate predicate
= a
-> true;
215 final IntPredicate memoize
= JCacheMemoize
.intPredicate(predicate
);
218 Assert
.assertNotNull("Memoized IntPredicate is NULL", memoize
);
225 public void shouldMemoizeLongPredicate() {
227 final LongPredicate predicate
= a
-> true;
230 final LongPredicate memoize
= JCacheMemoize
.longPredicate(predicate
);
233 Assert
.assertNotNull("Memoized LongPredicate is NULL", memoize
);
240 public void shouldMemoizeConsumer() {
242 final Consumer
<String
> consumer
= System
.out
::println
;
245 final Consumer
<String
> memoize
= JCacheMemoize
.consumer(consumer
);
248 Assert
.assertNotNull("Memoized Consumer is NULL", memoize
);
255 public void shouldMemoizeDoubleConsumer() {
257 final DoubleConsumer consumer
= System
.out
::println
;
260 final DoubleConsumer memoize
= JCacheMemoize
.doubleConsumer(consumer
);
263 Assert
.assertNotNull("Memoized DoubleConsumer is NULL", memoize
);
270 public void shouldMemoizeIntConsumer() {
272 final IntConsumer consumer
= System
.out
::println
;
275 final IntConsumer memoize
= JCacheMemoize
.intConsumer(consumer
);
278 Assert
.assertNotNull("Memoized IntConsumer is NULL", memoize
);
285 public void shouldMemoizeLongConsumer() {
287 final LongConsumer consumer
= System
.out
::println
;
290 final LongConsumer memoize
= JCacheMemoize
.longConsumer(consumer
);
293 Assert
.assertNotNull("Memoized LongConsumer is NULL", memoize
);
300 public void shouldMemoizeBiConsumer() {
302 final BiConsumer
<String
, String
> consumer
= (a
, b
) -> System
.out
.println(a
+ b
);
305 final BiConsumer
<String
, String
> memoize
= JCacheMemoize
.biConsumer(consumer
);
308 Assert
.assertNotNull("Memoized BiConsumer is NULL", memoize
);
315 public void shouldMemoizeBiFunction() {
317 final BiFunction
<String
, String
, String
> function
= (first
, second
) -> "test";
320 final BiFunction
<String
, String
, String
> memoize
= JCacheMemoize
.biFunction(function
);
323 Assert
.assertNotNull("Memoized BiFunction is NULL", memoize
);
330 public void shouldMemoizeBiPredicate() {
332 final BiPredicate
<String
, String
> biPredicate
= (first
, second
) -> true;
335 final BiPredicate
<String
, String
> memoize
= JCacheMemoize
.biPredicate(biPredicate
);
338 Assert
.assertNotNull("Memoized BiPredicate is NULL", memoize
);