Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties#2948
Open
vasiliy-mikhailov wants to merge 1 commit into
Open
Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties#2948vasiliy-mikhailov wants to merge 1 commit into
vasiliy-mikhailov wants to merge 1 commit into
Conversation
vasiliy-mikhailov
force-pushed
the
ijt-pr/e72199f
branch
from
July 12, 2026 08:21
6917198 to
99fb891
Compare
Contributor
|
I looked at it without AI and it makes sense. Lets see what copilot thinks about it. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds focused JUnit tests in tika-core to increase behavioral coverage of org.apache.tika.metadata.Metadata, especially around reserved X-TIKA: key guarding and MetadataWriteLimiter delegation semantics.
Changes:
- Added new unit tests asserting
Metadata.equalsdiffers when values differ under the same key. - Added tests for reserved-key blocking on untrusted metadata vs allowing writes after
setTrusted(true). - Added tests for
MetadataWriteLimiterbehavior, including “block all” and verifying delegation forset(...)overloads, plus small in-test limiter implementations.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+564
to
+572
| @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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Results
Scope: module
tika-core, target production classorg.apache.tika.metadata.Metadata, testsorg.apache.tika.metadata.TestMetadata. Measured with PIT 1.15.2 (junit5 plugin) under JDK 17, cleantest-compileforced before each run.The added tests kill 4 additional Metadata mutants and eliminate 2 survivors.
What this adds
Six focused unit tests on
Metadata, each asserting observable behavior or a documented contract:testValueDistinctMetadataNotEqual- twoMetadatainstances differing only in a value under the same key are not equal (value-basedequalscontract).testReservedKeyBlockedOnUntrustedMetadata- a reservedX-TIKA:key (built fromTikaCoreProperties.TIKA_META_PREFIX) added via a String write to an untrusted (default) instance is dropped, so untrusted callers cannot inject reserved keys.testReservedKeyAllowedOnTrustedMetadata- aftersetTrusted(true), the same reserved key is accepted.testWriteLimiterBlocksSet- a limiter that drops everything preventssetfrom persisting, so persistence stays under the limiter's control.testWriteLimiterInvokedOnSet-set(String, String)delegates to the limiter with the exact field and value (asserted via a recording spy limiter, not by re-reading a value the limiter itself wrote).testWriteLimiterInvokedOnSetProperty-set(Property, String)delegates to the limiter using the property'sgetName()and the given value.Scope
Tests-only. One file changed:
tika-core/src/test/java/org/apache/tika/metadata/TestMetadata.java(121 insertions, 0 deletions vs base). No production code, no fixtures, no build changes; Apache license headers unchanged.Disclosure
This PR was generated with an AI-assisted pipeline built around mutation testing (PIT). The pipeline mutates the target class (flipping conditions and changing boundary/edge cases) and runs the existing tests against each mutant; where a mutant survives (the existing tests do not catch that edge case), it writes a focused test for that case and reruns PIT to confirm the new test actually kills that specific mutant.