Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c9f6be

Browse filesBrowse files
committed
Update JSONCompareResult.java
Improved classe adding 2 new lists for missing and unexpected fileds.
1 parent ce4eebf commit 7c9f6be
Copy full SHA for 7c9f6be

File tree

Expand file treeCollapse file tree

1 file changed

+38
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+38
-3
lines changed
Open diff view settings
Collapse file

‎src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java
+38-3Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +85,8 @@ public List<FieldComparisonFailure> getFieldFailures() {
6985
* particular field
7086
* @deprecated Superseded by {@link #getFieldFailures()}
7187
*/
72-
public Object getActual() {
88+
@Deprecated
89+
public Object getActual() {
7390
return _actual;
7491
}
7592

@@ -81,7 +98,8 @@ public Object getActual() {
8198
* particular field
8299
* @deprecated Superseded by {@link #getFieldFailures()}
83100
*/
84-
public Object getExpected() {
101+
@Deprecated
102+
public Object getExpected() {
85103
return _expected;
86104
}
87105

@@ -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,7 +131,8 @@ public boolean isFailureOnField() {
99131
* not fail on a particular field
100132
* @deprecated Superseded by {@link #getFieldFailures()}
101133
*/
102-
public String getField() {
134+
@Deprecated
135+
public String getField() {
103136
return _field;
104137
}
105138

@@ -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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.