1 package com.atlassian.cache.ehcache;
2
3 import com.atlassian.cache.CacheLoader;
4 import com.atlassian.cache.ManagedCache;
5 import com.atlassian.cache.impl.WeakSupplier;
6 import java.util.function.Supplier;
7 import org.junit.Before;
8 import org.junit.Test;
9
10 import static org.junit.Assert.assertNotNull;
11
12 public class EhCacheManagerTest {
13
14 private EhCacheManagerHelper ehCacheManager;
15
16 @Before
17 public void setup() {
18 ehCacheManager = new EhCacheManagerHelper();
19 }
20
21 @Test
22 public void testShouldNotReturnNullCache() {
23 final String cacheName = "test";
24 ehCacheManager.getCache(cacheName, new CacheLoader<String, String>() {
25
26 @Override
27 public String load(String key) {
28 return "value";
29 }
30 });
31
32 WeakSupplier<ManagedCache> supplier = (WeakSupplier<ManagedCache>)ehCacheManager.getSupplier(cacheName);
33 supplier.clear();
34
35 assertNotNull("returned cache item should not be null", ehCacheManager.getCache(cacheName));
36 }
37
38
39
40
41 private static class EhCacheManagerHelper extends EhCacheManager {
42
43 public Supplier<ManagedCache> getSupplier(String cacheName) {
44 return this.caches.get(cacheName);
45 }
46 }
47
48 }