Copilot commented on code in PR #2948:
URL: https://github.com/apache/tika/pull/2948#discussion_r3601187678


##########
tika-core/src/test/java/org/apache/tika/metadata/TestMetadata.java:
##########
@@ -492,6 +495,124 @@ public void testToStringWithSingleEntry() {
         assertEquals("key=value1", m.toString());
     }
 
+    /**
+     * Two Metadata instances that differ only in a value under the same key
+     * must not be equal, so value-distinct metadata are never collapsed.
+     */
+    @Test
+    public void testValueDistinctMetadataNotEqual() {
+        Metadata m1 = new Metadata();
+        m1.add("k1", "v1");
+        Metadata m2 = new Metadata();
+        m2.add("k1", "v2");
+        assertNotEquals(m1, m2);
+    }
+
+    /**
+     * Reserved keys must be ignored when written to an untrusted Metadata
+     * instance (the default), so untrusted callers cannot inject them.
+     */
+    @Test
+    public void testReservedKeyBlockedOnUntrustedMetadata() {
+        String reservedKey = TikaCoreProperties.TIKA_META_PREFIX + "reserved";
+        Metadata m = new Metadata();
+        m.add(reservedKey, "value");
+        assertNull(m.get(reservedKey));
+    }
+
+    /**
+     * Once a Metadata instance is marked trusted, reserved keys are accepted.
+     */
+    @Test
+    public void testReservedKeyAllowedOnTrustedMetadata() {
+        String reservedKey = TikaCoreProperties.TIKA_META_PREFIX + "reserved";
+        Metadata m = new Metadata();
+        m.setTrusted(true);
+        m.add(reservedKey, "value");
+        assertEquals("value", m.get(reservedKey));
+    }
+
+    /**
+     * A write limiter that drops everything must prevent {@code set} from
+     * persisting a value, so persistence stays under the limiter's control.
+     */
+    @Test
+    public void testWriteLimiterBlocksSet() {
+        Metadata m = new Metadata(blockingLimiter());
+        m.set("key", "value");
+        assertNull(m.get("key"));
+    }
+
+    /**
+     * {@code set(String, String)} must delegate to the limiter with the exact
+     * field and value it was given.
+     */
+    @Test
+    public void testWriteLimiterInvokedOnSet() {
+        RecordingLimiter limiter = new RecordingLimiter();
+        Metadata m = new Metadata(limiter);
+        m.set("key", "value");
+        assertTrue(limiter.setCalled);
+        assertEquals("key", limiter.lastSetField);
+        assertEquals("value", limiter.lastSetValue);
+    }
+
+    /**
+     * The {@code set(Property, String)} overload must delegate to the limiter
+     * using the property's name and the given value.
+     */
+    @Test
+    public void testWriteLimiterInvokedOnSetProperty() {
+        RecordingLimiter limiter = new RecordingLimiter();
+        Metadata m = new Metadata(limiter);
+        m.set(TikaCoreProperties.TITLE, "title");
+        assertTrue(limiter.setCalled);
+        assertEquals(TikaCoreProperties.TITLE.getName(), limiter.lastSetField);
+        assertEquals("title", limiter.lastSetValue);
+    }

Review Comment:
   The PR title/description mentions coverage for composite properties, but 
this test currently exercises `set(Property, String)` only for a non-composite 
property (`TikaCoreProperties.TITLE`). If composite-property behavior is 
intended to be part of this PR’s scope, adjust this test to call `set` on an 
actual composite `Property` and assert that the limiter is invoked for each 
underlying property name (primary + aliases).



-- 
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