@@ -36,9 +36,9 @@ public void shouldReturnNonMachIfAllPropertiesAreNotFound() {
36
36
37
37
final var result = new LenientJsonObjectPartialMatcher ().jsonDiff (path , object1 , object2 , null );
38
38
39
- assertEquals (0 , result .similarityRate ());
40
39
assertEquals (path , result .path ());
41
40
new JsonDiffAsserter ()
41
+ .assertSimilarityRate (0 , 0 )
42
42
.assertMissingProperty (path .add (Path .PathItem .of ("a" )))
43
43
.assertMissingProperty (path .add (Path .PathItem .of ("b" )))
44
44
.validate (result );
@@ -60,11 +60,34 @@ public void shouldReturnNonMatchingPropertyIfAllPropertiesAreFoundWithoutMatch()
60
60
61
61
assertEquals (path , result .path ());
62
62
new JsonDiffAsserter ()
63
+ .assertSimilarityRate (60 , 0 )
63
64
.assertNonMatchingProperty (path .add (Path .PathItem .of ("a" )))
64
65
.assertNonMatchingProperty (path .add (Path .PathItem .of ("b" )))
65
66
.validate (result );
66
67
}
67
68
69
+ @ Test
70
+ public void shouldMixMatchingAndNotFoundPropertiesOnSameResult () {
71
+ final var object1 = new ObjectNode (null , Map .of (
72
+ "a" , TextNode .valueOf ("a" ),
73
+ "b" , TextNode .valueOf ("b" )
74
+ ));
75
+ final var object2 = new ObjectNode (null , Map .of (
76
+ "a" , TextNode .valueOf ("a" ),
77
+ "c" , TextNode .valueOf ("b" )
78
+ ));
79
+ final var parentMatcher = Mockito .mock (JsonMatcher .class );
80
+ Mockito .when (parentMatcher .diff (any (), any (), any ())).thenAnswer ((args ) -> fullMatchJsonDiff (args .getArgument (0 )));
81
+ final var result = new LenientJsonObjectPartialMatcher ().jsonDiff (path , object1 , object2 , parentMatcher );
82
+
83
+ assertEquals (path , result .path ());
84
+ new JsonDiffAsserter ()
85
+ .assertSimilarityRate (30 , 20 )
86
+ .assertMatchingProperty (path .add (Path .PathItem .of ("a" )))
87
+ .assertMissingProperty (path .add (Path .PathItem .of ("b" )))
88
+ .validate (result );
89
+ }
90
+
68
91
@ Test
69
92
public void shouldReturnFullMatchingPropertyAllPropertiesAreFoundAndMatch () {
70
93
final var object1 = new ObjectNode (null , Map .of (
@@ -81,6 +104,7 @@ public void shouldReturnFullMatchingPropertyAllPropertiesAreFoundAndMatch() {
81
104
82
105
assertEquals (path , result .path ());
83
106
new JsonDiffAsserter ()
107
+ .assertSimilarityRate (60 , 40 )
84
108
.assertMatchingProperty (path .add (Path .PathItem .of ("a" )))
85
109
.assertMatchingProperty (path .add (Path .PathItem .of ("b" )))
86
110
.validate (result );
@@ -102,6 +126,7 @@ public void shouldReturnSimilarityIfOnlyOneProperty() {
102
126
103
127
assertEquals (path , result .path ());
104
128
new JsonDiffAsserter ()
129
+ .assertSimilarityRate (20 , 40.0 / 3.0 )
105
130
.assertMatchingProperty (path .add (Path .PathItem .of ("a" )))
106
131
.assertMissingProperty (path .add (Path .PathItem .of ("b" )))
107
132
.assertMissingProperty (path .add (Path .PathItem .of ("c" )))
0 commit comments