anuragdy commented on code in PR #3939:
URL: https://github.com/apache/logging-log4j2/pull/3939#discussion_r2386801636


##########
log4j-api-test/src/test/java/org/apache/logging/log4j/spi/DefaultThreadContextMapTest.java:
##########
@@ -130,4 +132,144 @@ void threadLocalNotInheritableByDefault() {
     void threadLocalInheritableIfConfigured() {
         
threadLocalInheritableIfConfigured(createInheritableThreadContextMap());
     }
+
+    /**
+     * Test getCopy() with empty map
+     */
+    @Test
+    void testGetCopyWithEmptyMap() {
+        final DefaultThreadContextMap contextMap = new 
DefaultThreadContextMap();
+
+        // Verify map is empty
+        assertTrue(contextMap.isEmpty());
+        assertEquals(0, contextMap.size());
+
+        // Get copy of empty map
+        final Map<String, String> copy = contextMap.getCopy();
+
+        // Verify copy is empty HashMap
+        assertThat(copy).isInstanceOf(HashMap.class);
+        assertTrue(copy.isEmpty());
+        assertEquals(0, copy.size());
+
+        // Verify copy is independent
+        copy.put("test", "value");
+        assertTrue(contextMap.isEmpty());
+    }
+
+    /**
+     * Test getCopy() with single-element map
+     */
+    @Test
+    void testGetCopyWithSingleElement() {
+        final DefaultThreadContextMap contextMap = new 
DefaultThreadContextMap();
+
+        // Add single element
+        contextMap.put("key1", "value1");
+        assertEquals(1, contextMap.size());
+        assertEquals("value1", contextMap.get("key1"));
+
+        // Get copy
+        final Map<String, String> copy = contextMap.getCopy();
+
+        // Verify copy contains identical data
+        assertThat(copy).isInstanceOf(HashMap.class);
+        assertEquals(1, copy.size());
+        assertEquals("value1", copy.get("key1"));
+        assertTrue(copy.containsKey("key1"));
+
+        // Verify copy is independent
+        assertNotSame(copy, contextMap.toMap());
+        copy.put("key2", "value2");
+        assertEquals(1, contextMap.size());
+        assertFalse(contextMap.containsKey("key2"));
+    }
+
+    /**
+     * Test getCopy() with multiple elements
+     */
+    @Test
+    void testGetCopyWithMultipleElements() {
+        final DefaultThreadContextMap contextMap = new 
DefaultThreadContextMap();
+
+        // Add multiple elements
+        final Map<String, String> testData = new HashMap<>();
+        testData.put("key1", "value1");
+        testData.put("key2", "value2");
+        testData.put("key3", "value3");
+        testData.put("key4", "value4");
+        testData.put("key5", "value5");
+
+        contextMap.putAll(testData);
+        assertEquals(5, contextMap.size());
+
+        // Get copy
+        final Map<String, String> copy = contextMap.getCopy();
+
+        // Verify copy contains identical data
+        assertThat(copy).isInstanceOf(HashMap.class);
+        assertEquals(5, copy.size());
+
+        for (Map.Entry<String, String> entry : testData.entrySet()) {
+            assertTrue(copy.containsKey(entry.getKey()));
+            assertEquals(entry.getValue(), copy.get(entry.getKey()));
+        }
+

Review Comment:
   Good catch - you're right. The individual entry checks are redundant since 
`assertEquals(testData, copy)` already verifies the maps are equal. I'll remove 
the loop and keep the single assertion.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to