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

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

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

origin: apache/geode

@Override
public boolean matches(Object item) {
 if (!(item instanceof String)) {
  ObjectMapper om = new ObjectMapper();
  try {
   item = om.writeValueAsString(item);
  } catch (JsonProcessingException e) {
   failureMessage = e.getMessage();
   return false;
  }
 }
 JSONCompareResult result;
 try {
  result = JSONCompare.compareJSON(expectedJson, item.toString(), JSONCompareMode.LENIENT);
 } catch (JSONException jex) {
  failureMessage = jex.getMessage();
  return false;
 }
 if (result != null && result.failed()) {
  failureMessage = result.getMessage();
 }
 return result != null && result.passed();
}
origin: org.skyscreamer/jsonassert

/**
 * Asserts that the JSONArray provided matches the expected string.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expectedStr Expected JSON string
 * @param actualStr String to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode)
  throws JSONException {
  if (expectedStr==actualStr) return;
  if (expectedStr==null){
    throw new AssertionError("Expected string is null.");
  }else if (actualStr==null){
    throw new AssertionError("Actual string is null.");
  }
  JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: org.skyscreamer/jsonassert

/**
 * Asserts that the json string provided matches the expected string.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expectedStr Expected JSON string
 * @param actualStr String to compare
 * @param comparator Comparator
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, String expectedStr, String actualStr, JSONComparator comparator)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: org.skyscreamer/jsonassert

/**
 * Asserts that the JSONObject provided matches the expected JSONObject.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expected Expected JSONObject
 * @param actual JSONObject to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: org.skyscreamer/jsonassert

/**
 * Asserts that the JSONArray provided matches the expected JSONArray.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expected Expected JSONArray
 * @param actual JSONArray to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: skyscreamer/JSONassert

/**
 * Asserts that the JSONArray provided matches the expected string.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expectedStr Expected JSON string
 * @param actualStr String to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode)
  throws JSONException {
  if (expectedStr==actualStr) return;
  if (expectedStr==null){
    throw new AssertionError("Expected string is null.");
  }else if (actualStr==null){
    throw new AssertionError("Actual string is null.");
  }
  JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: skyscreamer/JSONassert

/**
 * Asserts that the JSONObject provided matches the expected JSONObject.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expected Expected JSONObject
 * @param actual JSONObject to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: skyscreamer/JSONassert

/**
 * Asserts that the JSONArray provided matches the expected JSONArray.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expected Expected JSONArray
 * @param actual JSONArray to compare
 * @param compareMode Specifies which comparison mode to use
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: skyscreamer/JSONassert

/**
 * Asserts that the json string provided matches the expected string.  If it isn't it throws an
 * {@link AssertionError}.
 *
 * @param message Error message to be displayed in case of assertion failure
 * @param expectedStr Expected JSON string
 * @param actualStr String to compare
 * @param comparator Comparator
 * @throws JSONException JSON parsing error
 */
public static void assertEquals(String message, String expectedStr, String actualStr, JSONComparator comparator)
  throws JSONException {
  JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator);
  if (result.failed()) {
    throw new AssertionError(getCombinedMessage(message, result.getMessage()));
  }
}
origin: org.springframework.boot/spring-boot-test

private JsonContentAssert assertNotFailed(JSONCompareResult result) {
  if (result.failed()) {
    throw new AssertionError("JSON Comparison failure: " + result.getMessage());
  }
  return this;
}
origin: uk.co.datumedge/hamcrest-json

static JSONComparisonResult resultOf(JSONCompareResult result) {
  if (result.failed()) {
    return diagnose(result);
  } else {
    return comparisonPassed();
  }
}
origin: hibernate/hibernate-search

  private static void assertJsonEquals(String expectedJson, String actualJson, JSONCompareMode mode) {
    try {
      JSONCompareResult result = JSONCompare.compareJSON( expectedJson, actualJson, mode );

      if ( result.failed() ) {
        throw new AssertionFailure( result.getMessage() + "; Actual: " + actualJson );
      }
    }
    catch (JSONException e) {
      throw new RuntimeException( e );
    }
  }
}
origin: osmlab/atlas

@Test
public void arrayCompare() throws JSONException
{
  final JSONCompareResult results = JSONCompare.compareJSON("[\"abc\"]", "[\"abc\"]",
      new RegularExpressionJSONComparator(JSONCompareMode.STRICT));
  Assert.assertFalse(results.failed());
}
origin: osmlab/atlas

@Test
public void structMissingItemsInArray() throws JSONException
{
  final JSONObject object1 = (JSONObject) JSONParser.parseJSON("{ \"a\": [ 1, 2 ] }");
  final JSONObject object2 = (JSONObject) JSONParser.parseJSON("{ \"a\": [ 1 ] }");
  final JSONCompareResult results = JSONCompare.compareJSON(object1, object2,
      new RegularExpressionJSONComparator(JSONCompareMode.STRICT));
  Assert.assertTrue(results.failed());
  Assert.assertEquals(1, results.getFieldMissing().size());
  Assert.assertEquals(0, results.getFieldUnexpected().size());
}
origin: osmlab/atlas

@Test
public void lenientOutOfOrderArraysContainingObjects() throws JSONException
{
  final JSONArray array1 = (JSONArray) JSONParser
      .parseJSON("[ { foo:\"123\" }, { foo:\"456\" } ]");
  final JSONArray array2 = (JSONArray) JSONParser
      .parseJSON("[ { foo:\"456\" }, { foo:\"123\" } ]");
  final JSONCompareResult results = JSONCompare.compareJSON(array1, array2,
      new RegularExpressionJSONComparator(JSONCompareMode.LENIENT));
  Assert.assertFalse(results.failed());
}
origin: osmlab/atlas

@Test
public void lenientOutOfOrderArraysMissingItems() throws JSONException
{
  final JSONArray array1 = (JSONArray) JSONParser.parseJSON("[\"123\", \"456\"]");
  final JSONArray array2 = (JSONArray) JSONParser.parseJSON("[\"789\", \"123\"]");
  final JSONCompareResult results = JSONCompare.compareJSON(array1, array2,
      new RegularExpressionJSONComparator(JSONCompareMode.LENIENT));
  Assert.assertTrue(results.failed());
}
origin: osmlab/atlas

@Test
public void nonExtensibleObjectTest() throws JSONException
{
  final JSONObject obj1 = (JSONObject) JSONParser.parseJSON("{ foo:\"abc\" }");
  final JSONObject obj2 = (JSONObject) JSONParser.parseJSON("{ foo:\"abc\", bar: \"def\" }");
  final JSONCompareResult results = JSONCompare.compareJSON(obj1, obj2,
      new RegularExpressionJSONComparator(JSONCompareMode.STRICT));
  Assert.assertTrue(results.failed());
}
origin: osmlab/atlas

@Test
public void lenientOutOfOrderArraysMixedAndMissingItems() throws JSONException
{
  final JSONArray array1 = (JSONArray) JSONParser.parseJSON("[ { foo:\"123\" }, 789 ]");
  final JSONArray array2 = (JSONArray) JSONParser.parseJSON("[ 456, { foo:\"123\" } ]");
  final JSONCompareResult results = JSONCompare.compareJSON(array1, array2,
      new RegularExpressionJSONComparator(JSONCompareMode.LENIENT));
  Assert.assertTrue(results.failed());
}
origin: osmlab/atlas

@Test
public void strictOutOfOrderArraysContainingArrays() throws JSONException
{
  final JSONArray array1 = (JSONArray) JSONParser.parseJSON("[ [\"123\" ], [\"456\" ] ]");
  final JSONArray array2 = (JSONArray) JSONParser.parseJSON("[ [\"456\" ], [\"123\" ] ]");
  final JSONCompareResult results = JSONCompare.compareJSON(array1, array2,
      new RegularExpressionJSONComparator(JSONCompareMode.STRICT_ORDER));
  Assert.assertTrue(results.failed());
}
origin: osmlab/atlas

@Test
public void strictOutOfOrderArraysContainingObjects() throws JSONException
{
  final JSONArray array1 = (JSONArray) JSONParser
      .parseJSON("[ { foo:\"123\" }, { bar:\"456\" } ]");
  final JSONArray array2 = (JSONArray) JSONParser
      .parseJSON("[ { bar:\"456\" }, { foo:\"123\" } ]");
  final JSONCompareResult results = JSONCompare.compareJSON(array1, array2,
      new RegularExpressionJSONComparator(JSONCompareMode.STRICT_ORDER));
  Assert.assertTrue(results.failed());
}
org.skyscreamer.jsonassertJSONCompareResultfailed

Javadoc

Did the comparison fail?

Popular methods of JSONCompareResult

  • getMessage
    Result message
  • passed
    Did the comparison pass?
  • fail
    Identify that the comparison failed
  • <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

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • scheduleAtFixedRate (Timer)
  • getSharedPreferences (Context)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JTextField (javax.swing)
  • Top plugins for WebStorm
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