This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new fc3096870c test(common): cover computeIfAbsent cache hit and miss. 
(#7870)
fc3096870c is described below

commit fc3096870ce52cadb2972a04df229d5be1a88af1
Author: Joker <[email protected]>
AuthorDate: Fri Oct 23 11:29:43 2026 +0800

    test(common): cover computeIfAbsent cache hit and miss. (#7870)
    
    Co-authored-by: Mrmr <[email protected]>
---
 .../apache/shenyu/common/utils/MapUtilsTest.java   | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git 
a/shenyu-common/src/test/java/org/apache/shenyu/common/utils/MapUtilsTest.java 
b/shenyu-common/src/test/java/org/apache/shenyu/common/utils/MapUtilsTest.java
index 29c097acc9..f2991531e9 100644
--- 
a/shenyu-common/src/test/java/org/apache/shenyu/common/utils/MapUtilsTest.java
+++ 
b/shenyu-common/src/test/java/org/apache/shenyu/common/utils/MapUtilsTest.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
 
 public class MapUtilsTest {
 
@@ -35,4 +36,29 @@ public class MapUtilsTest {
         assertEquals(stringStringMap.get("a").getClass(), String.class);
         assertEquals(stringStringMap.get("a"), "1");
     }
+
+    @Test
+    public void testComputeIfAbsentWithExistingValue() {
+        final Map<String, String> cache = new HashMap<>();
+        cache.put("name", "shenyu");
+
+        final String result = MapUtils.computeIfAbsent(cache, "name", key -> {
+            fail("Mapping function must not run when the value exists");
+            return "new-value";
+        });
+
+        assertEquals("shenyu", result);
+        assertEquals("shenyu", cache.get("name"));
+    }
+
+    @Test
+    public void testComputeIfAbsentWithMissingValue() {
+        final Map<String, String> cache = new HashMap<>();
+
+        final String result = MapUtils.computeIfAbsent(cache, "name", key -> 
"shenyu");
+
+        assertEquals("shenyu", result);
+        assertEquals("shenyu", cache.get("name"));
+    }
+
 }

Reply via email to