public class ArraySizeComparator extends DefaultComparator
Some typical usage idioms are listed below.
Assuming JSON to be verified is held in String variable ARRAY_OF_JSONOBJECTS and contains:
{a:[7, 8, 9]}
then:
To verify that array 'a' contains 3 elements:
JSONAssert.assertEquals("{a:[3]}", ARRAY_OF_JSONOBJECTS, new ArraySizeComparator(JSONCompareMode.LENIENT));
To verify that array 'a' contains between 2 and 6 elements:
JSONAssert.assertEquals("{a:[2,6]}", ARRAY_OF_JSONOBJECTS, new ArraySizeComparator(JSONCompareMode.LENIENT));
Constructor and Description |
---|
ArraySizeComparator(JSONCompareMode mode)
Create new ArraySizeComparator.
|
Modifier and Type | Method and Description |
---|---|
void |
compareJSONArray(String prefix,
org.json.JSONArray expected,
org.json.JSONArray actual,
JSONCompareResult result)
Expected array should consist of either 1 or 2 integer values that define
maximum and minimum valid lengths of the actual array.
|
compareJSON, compareValues
checkJsonObjectKeysActualInExpected, checkJsonObjectKeysExpectedInActual, compareJSON, compareJSON, compareJSONArrayOfJsonObjects, compareJSONArrayOfSimpleValues, compareJSONArrayWithStrictOrder, recursivelyCompareJSONArray
public ArraySizeComparator(JSONCompareMode mode)
mode
- comparison mode, has no impact on ArraySizeComparator but is
used by instance of superclass DefaultComparator to control
comparison of JSON items other than arrays.public void compareJSONArray(String prefix, org.json.JSONArray expected, org.json.JSONArray actual, JSONCompareResult result) throws org.json.JSONException
compareJSONArray
in interface JSONComparator
compareJSONArray
in class DefaultComparator
org.json.JSONException
Copyright © 2017. All rights reserved.