FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[TIKA-4841] Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties by vasiliy-mikhailov · Pull Request #2948 · apache/tika · GitHub

/ tika Public

[TIKA-4841] Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties - #2948

Merged
THausherr merged 10 commits into
apache:mainfrom
vasiliy-mikhailov:ijt-pr/e72199f
Aug 26, 2026
Merged

[TIKA-4841] Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties#2948
THausherr merged 10 commits into
apache:mainfrom
vasiliy-mikhailov:ijt-pr/e72199f

Conversation

vasiliy-mikhailov commented Jul 12, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Results

Scope: module tika-core, target production class org.apache.tika.metadata.Metadata, tests org.apache.tika.metadata.TestMetadata. Measured with PIT 1.15.2 (junit5 plugin) under JDK 17, clean test-compile forced before each run.

Metric Before After
Mutation kill rate 66/145 (46%) 70/145 (48%)
Mutants killed 66 70
Surviving mutants 7 5
Test strength 90% (66/73) 93% (70/75)
Line coverage (mutated class) 123/261 (47%) 132/261 (51%)

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 - two Metadata instances differing only in a value under the same key are not equal (value-based equals contract).
  • testReservedKeyBlockedOnUntrustedMetadata - a reserved X-TIKA: key (built from TikaCoreProperties.TIKA_META_PREFIX) added via a String write to an untrusted (default) instance is dropped, so untrusted callers cannot inject reserved keys.
  • testReservedKeyAllowedOnTrustedMetadata - after setTrusted(true), the same reserved key is accepted.
  • testWriteLimiterBlocksSet - a limiter that drops everything prevents set from 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's getName() 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.

Copy link
Copy Markdown
Contributor

I looked at it without AI and it makes sense. Lets see what copilot thinks about it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.equals differs 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 MetadataWriteLimiter behavior, including “block all” and verifying delegation for set(...) 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);
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

THausherr changed the title Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties [TIKA-4841] Add unit tests for Metadata reserved-key blocking, write limiter, and composite properties Aug 26, 2026
THausherr merged commit b08d4c2 into apache:main Aug 26, 2026
4 checks passed
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL