@@ -17,6 +17,8 @@ public class JSONCompareResult {
1717 private Object _expected ;
1818 private Object _actual ;
1919 private final List <FieldComparisonFailure > _fieldFailures = new ArrayList <FieldComparisonFailure >();
20+ private final List <FieldComparisonFailure > _fieldMissing = new ArrayList <FieldComparisonFailure >();
21+ private final List <FieldComparisonFailure > _fieldUnexpected = new ArrayList <FieldComparisonFailure >();
2022
2123 /**
2224 * Default constructor.
@@ -60,6 +62,20 @@ public String getMessage() {
6062 public List <FieldComparisonFailure > getFieldFailures () {
6163 return Collections .unmodifiableList (_fieldFailures );
6264 }
65+
66+ /**
67+ * Get the list of missed on field comparisons
68+ */
69+ public List <FieldComparisonFailure > getFieldMissing () {
70+ return Collections .unmodifiableList (_fieldMissing );
71+ }
72+
73+ /**
74+ * Get the list of failures on field comparisons
75+ */
76+ public List <FieldComparisonFailure > getFieldUnexpected () {
77+ return Collections .unmodifiableList (_fieldUnexpected );
78+ }
6379
6480 /**
6581 * Actual field value
@@ -69,6 +85,7 @@ public List<FieldComparisonFailure> getFieldFailures() {
6985 * particular field
7086 * @deprecated Superseded by {@link #getFieldFailures()}
7187 */
88+ @ Deprecated
7289 public Object getActual () {
7390 return _actual ;
7491 }
@@ -81,6 +98,7 @@ public Object getActual() {
8198 * particular field
8299 * @deprecated Superseded by {@link #getFieldFailures()}
83100 */
101+ @ Deprecated
84102 public Object getExpected () {
85103 return _expected ;
86104 }
@@ -91,6 +109,20 @@ public Object getExpected() {
91109 public boolean isFailureOnField () {
92110 return !_fieldFailures .isEmpty ();
93111 }
112+
113+ /**
114+ * Check if comparison failed with missing on any particular fields
115+ */
116+ public boolean isMissingOnField () {
117+ return !_fieldMissing .isEmpty ();
118+ }
119+
120+ /**
121+ * Check if comparison failed with unexpected on any particular fields
122+ */
123+ public boolean isUnexpectedOnField () {
124+ return !_fieldUnexpected .isEmpty ();
125+ }
94126
95127 /**
96128 * Dot-separated path the the field that failed comparison
@@ -99,6 +131,7 @@ public boolean isFailureOnField() {
99131 * not fail on a particular field
100132 * @deprecated Superseded by {@link #getFieldFailures()}
101133 */
134+ @ Deprecated
102135 public String getField () {
103136 return _field ;
104137 }
@@ -147,6 +180,7 @@ private String formatFailureMessage(String field, Object expected, Object actual
147180 }
148181
149182 public JSONCompareResult missing (String field , Object expected ) {
183+ _fieldMissing .add (new FieldComparisonFailure (field , expected , null ));
150184 fail (formatMissing (field , expected ));
151185 return this ;
152186 }
@@ -159,6 +193,7 @@ private String formatMissing(String field, Object expected) {
159193 }
160194
161195 public JSONCompareResult unexpected (String field , Object value ) {
196+ _fieldUnexpected .add (new FieldComparisonFailure (field , null , value ));
162197 fail (formatUnexpected (field , value ));
163198 return this ;
164199 }
0 commit comments