Skip to content

Commit 50dc7c5

Browse files
deblocktclaude
andcommitted
test: add tests for empty array vs missing property
Document that missing property does NOT match empty array (intentional design decision per PR description) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 210374a commit 50dc7c5

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/test/java/com/deblock/jsondiff/integration/NullEqualsEmptyArrayMatcherIntegrationTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,29 @@ public void shouldMatchMultipleNullAndEmptyArrayFields() {
8484

8585
assertEquals(100.0, diff.similarityRate());
8686
}
87+
88+
@Test
89+
public void shouldNotMatchEmptyArrayAndMissingProperty() {
90+
// Note: This case is intentionally NOT supported by NullEqualsEmptyArrayMatcher
91+
// Missing property is different from null or empty array
92+
final var expected = "{\"items\": []}";
93+
final var received = "{}";
94+
95+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
96+
97+
assertTrue(diff.similarityRate() < 100.0, "Empty array should not match missing property");
98+
}
99+
100+
@Test
101+
public void shouldNotMatchMissingPropertyAndEmptyArray() {
102+
// Note: This case is intentionally NOT supported by NullEqualsEmptyArrayMatcher
103+
final var expected = "{}";
104+
final var received = "{\"items\": []}";
105+
106+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
107+
108+
// With LenientJsonObjectPartialMatcher, extra properties are ignored
109+
// So this should match 100% (expected has no requirements)
110+
assertEquals(100.0, diff.similarityRate());
111+
}
87112
}

0 commit comments

Comments
 (0)