Skip to content

Commit 210374a

Browse files
deblocktclaude
andcommitted
refactor: move integration tests to dedicated folder
- Create integration test package - Move NullEqualsEmptyArrayMatcher integration tests to new class - Add tests for nested structures (deeply nested, inside arrays, multiple fields) - Keep only unit tests in NullEqualsEmptyArrayMatcherTest 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent cacc78d commit 210374a

File tree

2 files changed

+87
-50
lines changed

2 files changed

+87
-50
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.deblock.jsondiff.integration;
2+
3+
import com.deblock.jsondiff.DiffGenerator;
4+
import com.deblock.jsondiff.matcher.*;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
public class NullEqualsEmptyArrayMatcherIntegrationTest {
10+
11+
private final CompositeJsonMatcher jsonMatcher = new CompositeJsonMatcher(
12+
new NullEqualsEmptyArrayMatcher(),
13+
new LenientJsonArrayPartialMatcher(),
14+
new LenientJsonObjectPartialMatcher(),
15+
new StrictPrimitivePartialMatcher()
16+
);
17+
18+
@Test
19+
public void shouldMatchNullAndEmptyArray() {
20+
final var expected = "{\"items\": null}";
21+
final var received = "{\"items\": []}";
22+
23+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
24+
25+
assertEquals(100.0, diff.similarityRate());
26+
}
27+
28+
@Test
29+
public void shouldMatchEmptyArrayAndNull() {
30+
final var expected = "{\"items\": []}";
31+
final var received = "{\"items\": null}";
32+
33+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
34+
35+
assertEquals(100.0, diff.similarityRate());
36+
}
37+
38+
@Test
39+
public void shouldNotMatchNullAndNonEmptyArray() {
40+
final var expected = "{\"items\": null}";
41+
final var received = "{\"items\": [1, 2, 3]}";
42+
43+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
44+
45+
assertTrue(diff.similarityRate() < 100.0);
46+
}
47+
48+
@Test
49+
public void shouldMatchNullAndEmptyArrayInNestedObject() {
50+
final var expected = "{\"data\": {\"items\": null, \"name\": \"test\"}}";
51+
final var received = "{\"data\": {\"items\": [], \"name\": \"test\"}}";
52+
53+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
54+
55+
assertEquals(100.0, diff.similarityRate());
56+
}
57+
58+
@Test
59+
public void shouldMatchNullAndEmptyArrayInDeeplyNestedStructure() {
60+
final var expected = "{\"level1\": {\"level2\": {\"level3\": {\"items\": null}}}}";
61+
final var received = "{\"level1\": {\"level2\": {\"level3\": {\"items\": []}}}}";
62+
63+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
64+
65+
assertEquals(100.0, diff.similarityRate());
66+
}
67+
68+
@Test
69+
public void shouldMatchNullAndEmptyArrayInsideArray() {
70+
final var expected = "{\"data\": [{\"items\": null}, {\"items\": [1]}]}";
71+
final var received = "{\"data\": [{\"items\": []}, {\"items\": [1]}]}";
72+
73+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
74+
75+
assertEquals(100.0, diff.similarityRate());
76+
}
77+
78+
@Test
79+
public void shouldMatchMultipleNullAndEmptyArrayFields() {
80+
final var expected = "{\"array1\": null, \"array2\": null, \"value\": \"test\"}";
81+
final var received = "{\"array1\": [], \"array2\": [], \"value\": \"test\"}";
82+
83+
final var diff = DiffGenerator.diff(expected, received, jsonMatcher);
84+
85+
assertEquals(100.0, diff.similarityRate());
86+
}
87+
}

src/test/java/com/deblock/jsondiff/matcher/NullEqualsEmptyArrayMatcherTest.java

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -101,54 +101,4 @@ public void jsonDiff_shouldReturnUnMatch_whenNonEmptyArrayVsNull() {
101101
assertEquals(0.0, result.similarityRate());
102102
}
103103

104-
@Test
105-
public void integrationTest_shouldMatchNullAndEmptyArrayInJson() {
106-
final var expected = "{\"items\": null}";
107-
final var received = "{\"items\": []}";
108-
109-
final var jsonMatcher = new CompositeJsonMatcher(
110-
new NullEqualsEmptyArrayMatcher(),
111-
new LenientJsonArrayPartialMatcher(),
112-
new LenientJsonObjectPartialMatcher(),
113-
new StrictPrimitivePartialMatcher()
114-
);
115-
116-
final var diff = com.deblock.jsondiff.DiffGenerator.diff(expected, received, jsonMatcher);
117-
118-
assertEquals(100.0, diff.similarityRate());
119-
}
120-
121-
@Test
122-
public void integrationTest_shouldMatchEmptyArrayAndNullInJson() {
123-
final var expected = "{\"items\": []}";
124-
final var received = "{\"items\": null}";
125-
126-
final var jsonMatcher = new CompositeJsonMatcher(
127-
new NullEqualsEmptyArrayMatcher(),
128-
new LenientJsonArrayPartialMatcher(),
129-
new LenientJsonObjectPartialMatcher(),
130-
new StrictPrimitivePartialMatcher()
131-
);
132-
133-
final var diff = com.deblock.jsondiff.DiffGenerator.diff(expected, received, jsonMatcher);
134-
135-
assertEquals(100.0, diff.similarityRate());
136-
}
137-
138-
@Test
139-
public void integrationTest_shouldNotMatchNullAndNonEmptyArray() {
140-
final var expected = "{\"items\": null}";
141-
final var received = "{\"items\": [1, 2, 3]}";
142-
143-
final var jsonMatcher = new CompositeJsonMatcher(
144-
new NullEqualsEmptyArrayMatcher(),
145-
new LenientJsonArrayPartialMatcher(),
146-
new LenientJsonObjectPartialMatcher(),
147-
new StrictPrimitivePartialMatcher()
148-
);
149-
150-
final var diff = com.deblock.jsondiff.DiffGenerator.diff(expected, received, jsonMatcher);
151-
152-
assertTrue(diff.similarityRate() < 100.0);
153-
}
154104
}

0 commit comments

Comments
 (0)