mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add test
This commit is contained in:
@@ -96,7 +96,7 @@ public class SimpleCache<K, V> implements Iterable<Map.Entry<K, V>>, Serializabl
|
|||||||
*/
|
*/
|
||||||
public V get(final K key, final Predicate<V> validPredicate, final Func0<V> supplier) {
|
public V get(final K key, final Predicate<V> validPredicate, final Func0<V> supplier) {
|
||||||
V v = get(key);
|
V v = get(key);
|
||||||
if((null != validPredicate && false == validPredicate.test(v))){
|
if((null != validPredicate && null != v && false == validPredicate.test(v))){
|
||||||
v = null;
|
v = null;
|
||||||
}
|
}
|
||||||
if (null == v && null != supplier) {
|
if (null == v && null != supplier) {
|
||||||
|
@@ -46,6 +46,14 @@ public class SimpleCacheTest {
|
|||||||
Assert.assertEquals("value6", cache.get("key6", ()-> "value6"));
|
Assert.assertEquals("value6", cache.get("key6", ()-> "value6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getWithPredicateTest(){
|
||||||
|
// 检查predicate空指针
|
||||||
|
final SimpleCache<String, String> cache = new SimpleCache<>();
|
||||||
|
final String value = cache.get("abc", (v)-> v.equals("1"), () -> "123");
|
||||||
|
Assert.assertEquals("123", value);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getConcurrencyTest(){
|
public void getConcurrencyTest(){
|
||||||
final SimpleCache<String, String> cache = new SimpleCache<>();
|
final SimpleCache<String, String> cache = new SimpleCache<>();
|
||||||
|
Reference in New Issue
Block a user