12
12
import static org .junit .jupiter .api .Assertions .assertEquals ;
13
13
import static org .mockito .ArgumentMatchers .any ;
14
14
15
- public class LenientJsonArrayPartialMatcherTest {
15
+ class LenientJsonArrayPartialMatcherTest {
16
16
private final static Path path = Path .ROOT .add (Path .PathItem .of ("a" ));
17
17
18
18
@ Test
19
- public void shouldReturnFullMatchWhenAllItemsAreFound () {
19
+ void shouldReturnFullMatchWhenAllItemsAreFound () {
20
20
final var array1 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" )));
21
21
final var array2 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" )));
22
22
final var jsonMatcher = Mockito .mock (JsonMatcher .class );
@@ -33,7 +33,7 @@ public void shouldReturnFullMatchWhenAllItemsAreFound() {
33
33
}
34
34
35
35
@ Test
36
- public void shouldReturnFullMatchWhenAllItemsAreFoundWithBadOrder () {
36
+ void shouldReturnFullMatchWhenAllItemsAreFoundWithBadOrder () {
37
37
final var array1 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" )));
38
38
final var array2 = new ArrayNode (null , List .of (TextNode .valueOf ("b" ), TextNode .valueOf ("a" )));
39
39
final var jsonMatcher = Mockito .mock (JsonMatcher .class );
@@ -50,7 +50,22 @@ public void shouldReturnFullMatchWhenAllItemsAreFoundWithBadOrder() {
50
50
}
51
51
52
52
@ Test
53
- public void shouldReturnNoMatchWhenSameNumberItemWithNoMatch () {
53
+ void shouldReturnFullMatchForEmptyArray () {
54
+ final var array1 = new ArrayNode (null , List .of ());
55
+ final var array2 = new ArrayNode (null , List .of ());
56
+ final var jsonMatcher = Mockito .mock (JsonMatcher .class );
57
+ Mockito .when (jsonMatcher .diff (any (), any (), any ())).thenAnswer (this ::matchByEquality );
58
+
59
+ final var result = new LenientJsonArrayPartialMatcher ().jsonDiff (path , array1 , array2 , jsonMatcher );
60
+
61
+ assertEquals (100 , result .similarityRate ());
62
+ assertEquals (path , result .path ());
63
+ new JsonDiffAsserter ()
64
+ .validate (result );
65
+ }
66
+
67
+ @ Test
68
+ void shouldReturnNoMatchWhenSameNumberItemWithNoMatch () {
54
69
final var array1 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" )));
55
70
final var array2 = new ArrayNode (null , List .of (TextNode .valueOf ("c" ), TextNode .valueOf ("d" )));
56
71
final var jsonMatcher = Mockito .mock (JsonMatcher .class );
@@ -67,7 +82,7 @@ public void shouldReturnNoMatchWhenSameNumberItemWithNoMatch() {
67
82
}
68
83
69
84
@ Test
70
- public void shouldReturnPartialMatchWhenMissingItem () {
85
+ void shouldReturnPartialMatchWhenMissingItem () {
71
86
final var array1 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" )));
72
87
final var array2 = new ArrayNode (null , List .of (TextNode .valueOf ("b" )));
73
88
final var jsonMatcher = Mockito .mock (JsonMatcher .class );
@@ -84,7 +99,7 @@ public void shouldReturnPartialMatchWhenMissingItem() {
84
99
}
85
100
86
101
@ Test
87
- public void shouldReturnPartialMatchWhenExtraItems () {
102
+ void shouldReturnPartialMatchWhenExtraItems () {
88
103
final var array1 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("c" )));
89
104
final var array2 = new ArrayNode (null , List .of (TextNode .valueOf ("a" ), TextNode .valueOf ("b" ), TextNode .valueOf ("c" ), TextNode .valueOf ("d" )));
90
105
final var jsonMatcher = Mockito .mock (JsonMatcher .class );
0 commit comments