diff options
Diffstat (limited to 'spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java')
-rw-r--r-- | spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java new file mode 100644 index 00000000..5ede180c --- /dev/null +++ b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineCacheTests.java @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cache.caffeine; + +import com.github.benmanes.caffeine.cache.Caffeine; +import org.junit.Before; +import org.junit.Test; + +import org.springframework.cache.AbstractCacheTests; +import org.springframework.cache.Cache; + +import static org.junit.Assert.*; + +/** + * @author Ben Manes + * @author Stephane Nicoll + */ +public class CaffeineCacheTests extends AbstractCacheTests<CaffeineCache> { + + private com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCache; + + private CaffeineCache cache; + + @Before + public void setUp() { + nativeCache = Caffeine.newBuilder().build(); + cache = new CaffeineCache(CACHE_NAME, nativeCache); + } + + @Override + protected CaffeineCache getCache() { + return cache; + } + + @Override + protected Object getNativeCache() { + return nativeCache; + } + + @Test + public void testPutIfAbsentNullValue() throws Exception { + CaffeineCache cache = getCache(); + + Object key = new Object(); + Object value = null; + + assertNull(cache.get(key)); + assertNull(cache.putIfAbsent(key, value)); + assertEquals(value, cache.get(key).get()); + Cache.ValueWrapper wrapper = cache.putIfAbsent(key, "anotherValue"); + assertNotNull(wrapper); // A value is set but is 'null' + assertEquals(null, wrapper.get()); + assertEquals(value, cache.get(key).get()); // not changed + } + +} |