mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-09 14:31:17 +00:00
fix bug in compare utilities around json arrays with multiple optional elements
This commit is contained in:
parent
bb2e87c250
commit
d571f48376
@ -350,12 +350,15 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||||||
JsonArray expectedArray = (JsonArray) expectedJsonElement;
|
JsonArray expectedArray = (JsonArray) expectedJsonElement;
|
||||||
int expectedMin = countExpectedMin(expectedArray);
|
int expectedMin = countExpectedMin(expectedArray);
|
||||||
|
|
||||||
if (actualArray.size() > expectedArray.size() || actualArray.size() < expectedMin)
|
int as = actualArray.size();
|
||||||
return createNotEqualMessage("array item count differs at " + path, Integer.toString(expectedArray.size()), Integer.toString(actualArray.size()));
|
int es = expectedArray.size();
|
||||||
|
int oc = optionalCount(expectedArray);
|
||||||
|
if (as > es || as < expectedMin)
|
||||||
|
return createNotEqualMessage("array item count differs at " + path, Integer.toString(es), Integer.toString(as));
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (int i = 0; i < expectedArray.size(); i++) {
|
for (int i = 0; i < es; i++) {
|
||||||
if (c >= actualArray.size()) {
|
if (c >= as) {
|
||||||
if (i == expectedArray.size() - 1 && isOptional(expectedArray.get(i))) {
|
if (i >= es - oc && isOptional(expectedArray.get(i))) {
|
||||||
return null; // this is OK
|
return null; // this is OK
|
||||||
} else {
|
} else {
|
||||||
return "One or more array items did not match at "+path+" starting at index "+i;
|
return "One or more array items did not match at "+path+" starting at index "+i;
|
||||||
@ -375,7 +378,20 @@ public class CompareUtilities extends BaseTestingUtilities {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOptional(JsonElement e) {
|
private int optionalCount(JsonArray arr) {
|
||||||
|
int c = 0;
|
||||||
|
for (JsonElement e : arr) {
|
||||||
|
if (e.isJsonObject()) {
|
||||||
|
JsonObject j = e.asJsonObject();
|
||||||
|
if (j.has("$optional$") && j.asBoolean("$optional$")) {
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isOptional(JsonElement e) {
|
||||||
return e.isJsonObject() && e.asJsonObject().has("$optional$");
|
return e.isJsonObject() && e.asJsonObject().has("$optional$");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user