diff --git a/hutool-core/src/test/java/cn/hutool/v7/core/cache/SimpleCacheTest.java b/hutool-core/src/test/java/cn/hutool/v7/core/cache/SimpleCacheTest.java index 6b5503230..6ce047622 100644 --- a/hutool-core/src/test/java/cn/hutool/v7/core/cache/SimpleCacheTest.java +++ b/hutool-core/src/test/java/cn/hutool/v7/core/cache/SimpleCacheTest.java @@ -22,6 +22,11 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class SimpleCacheTest { @BeforeEach @@ -82,4 +87,36 @@ public class SimpleCacheTest { Assertions.assertTrue(tester.getInterval() > 0); Assertions.assertEquals("aaaValue", cache.get("aaa")); } + + @Test + void removeTest(){ + final SimpleCache cache = new SimpleCache<>(); + cache.put("key1", "value1"); + cache.get("key1"); + cache.put("key2", "value2"); + cache.get("key2"); + cache.put("key3", "value3"); + cache.get("key3"); + cache.put("key4", "value4"); + cache.get("key4"); + cache.get("key5", ()->"value5"); + + String key = null; + for (Map.Entry entry : cache) { + if ("value3".equals(entry.getValue())) { + key = entry.getKey(); + break; + } + } + + if(null != key){ + cache.remove(key); + } + + assertEquals("value1", cache.get("key1")); + assertEquals("value2", cache.get("key2")); + assertEquals("value4", cache.get("key4")); + assertEquals("value5", cache.get("key5")); + assertNull(cache.get("key3")); + } }