fix #68
[memoization.java.git] / memoization-guava / src / test / java / de / xn__ho_hia / memoization / guava / GuavaCacheBasedSupplierMemoizerTest.java
blob975438c71733e78ae784de6ff9b8bf3d1084faa1
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.guava;
9 import java.util.function.Supplier;
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;
21 /**
25 @SuppressWarnings({ CompilerWarnings.NLS, CompilerWarnings.STATIC_METHOD })
26 public class GuavaCacheBasedSupplierMemoizerTest {
28 /** Captures expected exceptions. */
29 @Rule
30 public ExpectedException thrown = ExpectedException.none();
32 /**
35 @Test
36 public void shouldAcceptLoadingCacheAndKeySupplier() {
37 // given
38 final Supplier<String> supplier = () -> "value";
39 final Supplier<String> keySupplier = () -> "key";
40 final Cache<String, String> cache = CacheBuilder.newBuilder().build();
42 // when
43 final GuavaCacheBasedSupplierMemoizer<String, String> memoizer = new GuavaCacheBasedSupplierMemoizer<>(cache,
44 keySupplier, supplier);
46 // then
47 Assert.assertNotNull(memoizer);
50 /**
53 @Test
54 public void shouldReturnSuppliedValue() {
55 // given
56 final Supplier<String> supplier = () -> "value";
57 final Supplier<String> keySupplier = () -> "key";
58 final Cache<String, String> cache = CacheBuilder.newBuilder().build();
60 // when
61 final GuavaCacheBasedSupplierMemoizer<String, String> memoizer = new GuavaCacheBasedSupplierMemoizer<>(cache,
62 keySupplier, supplier);
64 // then
65 Assert.assertEquals("value", memoizer.get());