fix #146
[memoization.java.git] / memoization-jcache / src / test / java / de / xn__ho_hia / memoization / jcache / JCacheMemoizeDefaultsTest.java
blobb1f754ff78f60350cfef7277d21489615ed3cae7
1 /*
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
5 * in the LICENSE file.
6 */
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;
35 /**
38 @SuppressWarnings({ CompilerWarnings.NLS, CompilerWarnings.STATIC_METHOD })
39 public class JCacheMemoizeDefaultsTest {
41 /**
44 @Test
45 public void shouldMemoizeSupplier() {
46 // given
47 final Supplier<String> supplier = () -> "test";
49 // when
50 final Supplier<String> memoize = JCacheMemoize.supplier(supplier);
52 // then
53 Assert.assertNotNull("Memoized Supplier is NULL", memoize);
56 /**
59 @Test
60 public void shouldMemoizeBooleanSupplier() {
61 // given
62 final BooleanSupplier supplier = () -> true;
64 // when
65 final BooleanSupplier memoize = JCacheMemoize.booleanSupplier(supplier);
67 // then
68 Assert.assertNotNull("Memoized BooleanSupplier is NULL", memoize);
71 /**
74 @Test
75 public void shouldMemoizeDoubleSupplier() {
76 // given
77 final DoubleSupplier supplier = () -> 123.456D;
79 // when
80 final DoubleSupplier memoize = JCacheMemoize.doubleSupplier(supplier);
82 // then
83 Assert.assertNotNull("Memoized DoubleSupplier is NULL", memoize);
86 /**
89 @Test
90 public void shouldMemoizeIntSupplier() {
91 // given
92 final IntSupplier supplier = () -> 123;
94 // when
95 final IntSupplier memoize = JCacheMemoize.intSupplier(supplier);
97 // then
98 Assert.assertNotNull("Memoized IntSupplier is NULL", memoize);
104 @Test
105 public void shouldMemoizeLongSupplier() {
106 // given
107 final LongSupplier supplier = () -> 123L;
109 // when
110 final LongSupplier memoize = JCacheMemoize.longSupplier(supplier);
112 // then
113 Assert.assertNotNull("Memoized LongSupplier is NULL", memoize);
119 @Test
120 public void shouldMemoizeFunction() {
121 // given
122 final Function<String, String> function = a -> "test";
124 // when
125 final Function<String, String> memoize = JCacheMemoize.function(function);
127 // then
128 Assert.assertNotNull("Memoized Function is NULL", memoize);
134 @Test
135 public void shouldMemoizeIntFunction() {
136 // given
137 final IntFunction<String> function = a -> "test";
139 // when
140 final IntFunction<String> memoize = JCacheMemoize.intFunction(function);
142 // then
143 Assert.assertNotNull("Memoized IntFunction is NULL", memoize);
149 @Test
150 public void shouldMemoizeLongFunction() {
151 // given
152 final LongFunction<String> function = a -> "test";
154 // when
155 final LongFunction<String> memoize = JCacheMemoize.longFunction(function);
157 // then
158 Assert.assertNotNull("Memoized LongFunction is NULL", memoize);
164 @Test
165 public void shouldMemoizeDoubleFunction() {
166 // given
167 final DoubleFunction<String> function = a -> "test";
169 // when
170 final DoubleFunction<String> memoize = JCacheMemoize.doubleFunction(function);
172 // then
173 Assert.assertNotNull("Memoized DoubleFunction is NULL", memoize);
179 @Test
180 public void shouldMemoizePredicate() {
181 // given
182 final Predicate<String> predicate = a -> true;
184 // when
185 final Predicate<String> memoize = JCacheMemoize.predicate(predicate);
187 // then
188 Assert.assertNotNull("Memoized Predicate is NULL", memoize);
194 @Test
195 public void shouldMemoizeDoublePredicate() {
196 // given
197 final DoublePredicate predicate = a -> true;
199 // when
200 final DoublePredicate memoize = JCacheMemoize.doublePredicate(predicate);
202 // then
203 Assert.assertNotNull("Memoized DoublePredicate is NULL", memoize);
209 @Test
210 public void shouldMemoizeIntPredicate() {
211 // given
212 final IntPredicate predicate = a -> true;
214 // when
215 final IntPredicate memoize = JCacheMemoize.intPredicate(predicate);
217 // then
218 Assert.assertNotNull("Memoized IntPredicate is NULL", memoize);
224 @Test
225 public void shouldMemoizeLongPredicate() {
226 // given
227 final LongPredicate predicate = a -> true;
229 // when
230 final LongPredicate memoize = JCacheMemoize.longPredicate(predicate);
232 // then
233 Assert.assertNotNull("Memoized LongPredicate is NULL", memoize);
239 @Test
240 public void shouldMemoizeConsumer() {
241 // given
242 final Consumer<String> consumer = System.out::println;
244 // when
245 final Consumer<String> memoize = JCacheMemoize.consumer(consumer);
247 // then
248 Assert.assertNotNull("Memoized Consumer is NULL", memoize);
254 @Test
255 public void shouldMemoizeDoubleConsumer() {
256 // given
257 final DoubleConsumer consumer = System.out::println;
259 // when
260 final DoubleConsumer memoize = JCacheMemoize.doubleConsumer(consumer);
262 // then
263 Assert.assertNotNull("Memoized DoubleConsumer is NULL", memoize);
269 @Test
270 public void shouldMemoizeIntConsumer() {
271 // given
272 final IntConsumer consumer = System.out::println;
274 // when
275 final IntConsumer memoize = JCacheMemoize.intConsumer(consumer);
277 // then
278 Assert.assertNotNull("Memoized IntConsumer is NULL", memoize);
284 @Test
285 public void shouldMemoizeLongConsumer() {
286 // given
287 final LongConsumer consumer = System.out::println;
289 // when
290 final LongConsumer memoize = JCacheMemoize.longConsumer(consumer);
292 // then
293 Assert.assertNotNull("Memoized LongConsumer is NULL", memoize);
299 @Test
300 public void shouldMemoizeBiConsumer() {
301 // given
302 final BiConsumer<String, String> consumer = (a, b) -> System.out.println(a + b);
304 // when
305 final BiConsumer<String, String> memoize = JCacheMemoize.biConsumer(consumer);
307 // then
308 Assert.assertNotNull("Memoized BiConsumer is NULL", memoize);
314 @Test
315 public void shouldMemoizeBiFunction() {
316 // given
317 final BiFunction<String, String, String> function = (first, second) -> "test";
319 // when
320 final BiFunction<String, String, String> memoize = JCacheMemoize.biFunction(function);
322 // then
323 Assert.assertNotNull("Memoized BiFunction is NULL", memoize);
329 @Test
330 public void shouldMemoizeBiPredicate() {
331 // given
332 final BiPredicate<String, String> biPredicate = (first, second) -> true;
334 // when
335 final BiPredicate<String, String> memoize = JCacheMemoize.biPredicate(biPredicate);
337 // then
338 Assert.assertNotNull("Memoized BiPredicate is NULL", memoize);