Skip to content

More verbose diff view on assertion error #91

Open
@semisiu

Description

@semisiu

We'd like to have an ability to provide more verbose, or generally custom json diff view on assertion error (such like un*x diff -y does).

For example, given two jsons:

{
  "id": "101",
  "key": {
    "a": "value",
    "b": "xyz",
    "c": 201
  }
}

and:

{
  "id": "102",
  "key": {
    "a": "value",
    "d": [1, 2]
  }
}

calling:

DiffViewProvider diffViewProvider = new LinuxAlikeDiffViewProvider();
JSONAssert.assertEquals(json1, json2, true, diffViewProvider);

would throw an AssertionError with original message and additionally (optionally) more verbose diff:

java.lang.AssertionError: id
Expected: 101
     got: 102
 ; key
Expected: b
     but none found
 ; key
Expected: c
     but none found
 ; key
Unexpected: d

Actual json vs expected json:
{                        {
  "id": "101",        |    "id": "102",
  "key": {                 "key": {
    "a": "value",            "a": "value",
    "b": "xyz",       |      "d": [1, 2]
    "c": 201          <
  }                        }
}                        }

More json-conscious diff:

{                        {
  "id": "101",        |    "id": "102",
  "key": {                 "key": {
    "a": "value",            "a": "value",
    "b": "xyz",       <
    "c": 201          <
                      >      "d": [1, 2]
  }                        }
}                        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions