Tabnine Logo
JSONCompareResult.fail
Code IndexAdd Tabnine to your IDE (free)

How to use
fail
method
in
org.skyscreamer.jsonassert.JSONCompareResult

Best Java code snippets using org.skyscreamer.jsonassert.JSONCompareResult.fail (Showing top 20 results out of 315)

origin: org.skyscreamer/jsonassert

/**
 * Identify the missing field
 * @param field missing field
 * @param expected expected result
 * @return result of comparison
 */
public JSONCompareResult missing(String field, Object expected) {
  _fieldMissing.add(new FieldComparisonFailure(field, expected, null));
  fail(formatMissing(field, expected));
  return this;
}
origin: org.skyscreamer/jsonassert

/**
 * Identify unexpected field
 * @param field unexpected field
 * @param actual actual result
 * @return result of comparison
 */
public JSONCompareResult unexpected(String field, Object actual) {
  _fieldUnexpected.add(new FieldComparisonFailure(field, null, actual));
  fail(formatUnexpected(field, actual));
  return this;
}
origin: org.skyscreamer/jsonassert

@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result)
    throws JSONException {
  if (areNumbers(expectedValue, actualValue)) {
    if (areNotSameDoubles(expectedValue, actualValue)) {
      result.fail(prefix, expectedValue, actualValue);
    }
  } else if (expectedValue.getClass().isAssignableFrom(actualValue.getClass())) {
    if (expectedValue instanceof JSONArray) {
      compareJSONArray(prefix, (JSONArray) expectedValue, (JSONArray) actualValue, result);
    } else if (expectedValue instanceof JSONObject) {
      compareJSON(prefix, (JSONObject) expectedValue, (JSONObject) actualValue, result);
    } else if (!expectedValue.equals(actualValue)) {
      result.fail(prefix, expectedValue, actualValue);
    }
  } else {
    result.fail(prefix, expectedValue, actualValue);
  }
}
origin: org.skyscreamer/jsonassert

@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
  Customization customization = getCustomization(prefix);
  if (customization != null) {
    try {
      if (!customization.matches(prefix, actualValue, expectedValue, result)) {
        result.fail(prefix, expectedValue, actualValue);
      }
    }
    catch (ValueMatcherException e) {
      result.fail(prefix, e);
    }
  } else {
    super.compareValues(prefix, expectedValue, actualValue, result);
  }
}
origin: org.skyscreamer/jsonassert

/**
 * Identify that the comparison failed
 * @param field Which field failed
 * @param expected Expected result
 * @param actual Actual result
 * @return result of comparision
 */
public JSONCompareResult fail(String field, Object expected, Object actual) {
  _fieldFailures.add(new FieldComparisonFailure(field, expected, actual));
  this._field = field;
  this._expected = expected;
  this._actual = actual;
  fail(formatFailureMessage(field, expected, actual));
  return this;
}
origin: org.skyscreamer/jsonassert

String arrayPrefix = prefix + "[]";
if (expected.length() < 1 || expected.length() > 2) {
  result.fail(MessageFormat
      .format("{0}: invalid expectation: expected array should contain either 1 or 2 elements but contains {1} elements",
          arrayPrefix, expected.length()));
  result.fail(MessageFormat
      .format("{0}: invalid expectation: {1}expected array size ''{2}'' not a number",
          arrayPrefix, (expected.length() == 1? "": "minimum "), expected.get(0)));
  result.fail(MessageFormat
      .format("{0}: invalid expectation: maximum expected array size ''{1}'' not a number",
          arrayPrefix, expected.get(1)));
  result.fail(MessageFormat
      .format("{0}: invalid expectation: minimum expected array size ''{1}'' negative",
          arrayPrefix, minExpectedLength));
    : minExpectedLength;
if (maxExpectedLength < minExpectedLength) {
  result.fail(MessageFormat
      .format("{0}: invalid expectation: maximum expected array size ''{1}'' less than minimum expected array size ''{2}''",
          arrayPrefix, maxExpectedLength, minExpectedLength));
  result.fail(
      arrayPrefix,
      MessageFormat.format(
origin: org.skyscreamer/jsonassert

protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
  Map<Object, Integer> expectedCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(expected));
  Map<Object, Integer> actualCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(actual));
  for (Object o : expectedCount.keySet()) {
    if (!actualCount.containsKey(o)) {
      result.missing(key + "[]", o);
    } else if (!actualCount.get(o).equals(expectedCount.get(o))) {
      result.fail(key + "[]: Expected " + expectedCount.get(o) + " occurrence(s) of " + o
          + " but got " + actualCount.get(o) + " occurrence(s)");
    }
  }
  for (Object o : actualCount.keySet()) {
    if (!expectedCount.containsKey(o)) {
      result.unexpected(key + "[]", o);
    }
  }
}
origin: org.skyscreamer/jsonassert

result.fail(key + "[" + i + "] Could not find match for element " + expectedElement);
return;
origin: org.skyscreamer/jsonassert

/**
 * Compares {@link JSONString} provided to the expected {@code JSONString}, checking that the
 * {@link org.json.JSONString#toJSONString()} are equal.
 *
 * @param expected Expected {@code JSONstring}
 * @param actual   {@code JSONstring} to compare
 * @return result of the comparison
 */
public static JSONCompareResult compareJson(final JSONString expected, final JSONString actual) {
  final JSONCompareResult result = new JSONCompareResult();
  final String expectedJson = expected.toJSONString();
  final String actualJson = actual.toJSONString();
  if (!expectedJson.equals(actualJson)) {
   result.fail("");
  }
  return result;
}
origin: org.skyscreamer/jsonassert

/**
 * Identify that the comparison failed
 * @param field Which field failed
 * @param exception exception containing details of match failure
 * @return result of comparision
 */
public JSONCompareResult fail(String field, ValueMatcherException exception) {
  fail(field + ": " + exception.getMessage(), exception.getExpected(), exception.getActual());
  return this;
}
origin: org.skyscreamer/jsonassert

@Override
public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result)
    throws JSONException {
  if (expected.length() != actual.length()) {
    result.fail(prefix + "[]: Expected " + expected.length() + " values but got " + actual.length());
    return;
  } else if (expected.length() == 0) {
    return; // Nothing to compare
  }
  if (mode.hasStrictOrder()) {
    compareJSONArrayWithStrictOrder(prefix, expected, actual, result);
  } else if (allSimpleValues(expected)) {
    compareJSONArrayOfSimpleValues(prefix, expected, actual, result);
  } else if (allJSONObjects(expected)) {
    compareJSONArrayOfJsonObjects(prefix, expected, actual, result);
  } else {
    // An expensive last resort
    recursivelyCompareJSONArray(prefix, expected, actual, result);
  }
}
origin: org.skyscreamer/jsonassert

/**
 * Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of
 * the comparison.
 * @param expectedStr Expected JSON string
 * @param actualStr JSON string to compare
 * @param comparator Comparator to use
 * @return result of the comparison
 * @throws JSONException JSON parsing error
 * @throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr
 */
public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator)
    throws JSONException {
  Object expected = JSONParser.parseJSON(expectedStr);
  Object actual = JSONParser.parseJSON(actualStr);
  if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) {
    return compareJSON((JSONObject) expected, (JSONObject) actual, comparator);
  }
  else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) {
    return compareJSON((JSONArray)expected, (JSONArray)actual, comparator);
  }
  else if (expected instanceof JSONString && actual instanceof JSONString) {
    return compareJson((JSONString) expected, (JSONString) actual);
  }
  else if (expected instanceof JSONObject) {
    return new JSONCompareResult().fail("", expected, actual);
  }
  else {
    return new JSONCompareResult().fail("", expected, actual);
  }
}
origin: skyscreamer/JSONassert

/**
 * Identify the missing field
 * @param field missing field
 * @param expected expected result
 * @return result of comparison
 */
public JSONCompareResult missing(String field, Object expected) {
  _fieldMissing.add(new FieldComparisonFailure(field, expected, null));
  fail(formatMissing(field, expected));
  return this;
}
origin: skyscreamer/JSONassert

@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result)
    throws JSONException {
  if (areNumbers(expectedValue, actualValue)) {
    if (areNotSameDoubles(expectedValue, actualValue)) {
      result.fail(prefix, expectedValue, actualValue);
    }
  } else if (expectedValue.getClass().isAssignableFrom(actualValue.getClass())) {
    if (expectedValue instanceof JSONArray) {
      compareJSONArray(prefix, (JSONArray) expectedValue, (JSONArray) actualValue, result);
    } else if (expectedValue instanceof JSONObject) {
      compareJSON(prefix, (JSONObject) expectedValue, (JSONObject) actualValue, result);
    } else if (!expectedValue.equals(actualValue)) {
      result.fail(prefix, expectedValue, actualValue);
    }
  } else {
    result.fail(prefix, expectedValue, actualValue);
  }
}
origin: skyscreamer/JSONassert

/**
 * Identify unexpected field
 * @param field unexpected field
 * @param actual actual result
 * @return result of comparison
 */
public JSONCompareResult unexpected(String field, Object actual) {
  _fieldUnexpected.add(new FieldComparisonFailure(field, null, actual));
  fail(formatUnexpected(field, actual));
  return this;
}
origin: skyscreamer/JSONassert

@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
  Customization customization = getCustomization(prefix);
  if (customization != null) {
    try {
      if (!customization.matches(prefix, actualValue, expectedValue, result)) {
        result.fail(prefix, expectedValue, actualValue);
      }
    }
    catch (ValueMatcherException e) {
      result.fail(prefix, e);
    }
  } else {
    super.compareValues(prefix, expectedValue, actualValue, result);
  }
}
origin: skyscreamer/JSONassert

/**
 * Identify that the comparison failed
 * @param field Which field failed
 * @param expected Expected result
 * @param actual Actual result
 * @return result of comparision
 */
public JSONCompareResult fail(String field, Object expected, Object actual) {
  _fieldFailures.add(new FieldComparisonFailure(field, expected, actual));
  this._field = field;
  this._expected = expected;
  this._actual = actual;
  fail(formatFailureMessage(field, expected, actual));
  return this;
}
origin: skyscreamer/JSONassert

protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException {
  Map<Object, Integer> expectedCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(expected));
  Map<Object, Integer> actualCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(actual));
  for (Object o : expectedCount.keySet()) {
    if (!actualCount.containsKey(o)) {
      result.missing(key + "[]", o);
    } else if (!actualCount.get(o).equals(expectedCount.get(o))) {
      result.fail(key + "[]: Expected " + expectedCount.get(o) + " occurrence(s) of " + o
          + " but got " + actualCount.get(o) + " occurrence(s)");
    }
  }
  for (Object o : actualCount.keySet()) {
    if (!expectedCount.containsKey(o)) {
      result.unexpected(key + "[]", o);
    }
  }
}
origin: skyscreamer/JSONassert

/**
 * Compares {@link JSONString} provided to the expected {@code JSONString}, checking that the
 * {@link org.json.JSONString#toJSONString()} are equal.
 *
 * @param expected Expected {@code JSONstring}
 * @param actual   {@code JSONstring} to compare
 * @return result of the comparison
 */
public static JSONCompareResult compareJson(final JSONString expected, final JSONString actual) {
  final JSONCompareResult result = new JSONCompareResult();
  final String expectedJson = expected.toJSONString();
  final String actualJson = actual.toJSONString();
  if (!expectedJson.equals(actualJson)) {
   result.fail("");
  }
  return result;
}
origin: skyscreamer/JSONassert

/**
 * Identify that the comparison failed
 * @param field Which field failed
 * @param exception exception containing details of match failure
 * @return result of comparision
 */
public JSONCompareResult fail(String field, ValueMatcherException exception) {
  fail(field + ": " + exception.getMessage(), exception.getExpected(), exception.getActual());
  return this;
}
org.skyscreamer.jsonassertJSONCompareResultfail

Javadoc

Identify that the comparison failed

Popular methods of JSONCompareResult

  • getMessage
    Result message
  • failed
    Did the comparison fail?
  • passed
    Did the comparison pass?
  • <init>
  • getFieldFailures
    Get the list of failures on field comparisons
  • missing
    Identify the missing field
  • unexpected
    Identify unexpected field
  • describe
  • formatFailureMessage
  • formatMissing
  • formatUnexpected
  • getFieldMissing
    Get the list of missed on field comparisons
  • formatUnexpected,
  • getFieldMissing,
  • getFieldUnexpected

Popular in Java

  • Updating database using SQL prepared statement
  • getContentResolver (Context)
  • onRequestPermissionsResult (Fragment)
  • requestLocationUpdates (LocationManager)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now