Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a separate exception when a test operation fails #201

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ else if (value.isObject())
public void test(JsonPointer path, JsonNode value) throws JsonPointerEvaluationException {
JsonNode valueNode = path.evaluate(target);
if (!valueNode.equals(value))
throw new JsonPatchApplicationException(
"Expected " + show(value) + " but found " + show(valueNode), Operation.TEST, path);
throw new JsonPatchTestFailedException(
"Expected " + show(value) + " but found " + show(valueNode), path);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipkart.zjsonpatch;

public class JsonPatchTestFailedException extends JsonPatchApplicationException {
public JsonPatchTestFailedException(String message, JsonPointer path) {
super(message, Operation.TEST, path);
}
}
5 changes: 4 additions & 1 deletion src/test/resources/testdata/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
{
"op": [{ "op": "test", "path": "", "value": true }],
"node": [ 1, 2 ],
"type": "com.flipkart.zjsonpatch.JsonPatchTestFailedException",
"message": "Expected value true but found array at root"
},
{
"op": [{ "op": "test", "path": "/x", "value": -30.000 }],
"node": { "x": -29.020 },
"type": "com.flipkart.zjsonpatch.JsonPatchTestFailedException",
"message": "Expected value -30.0 but found value -29.02 at /x"
},
{
"op": [{ "op": "test", "path": "/x", "value": null }],
"node": { "x": 3 },
"type": "com.flipkart.zjsonpatch.JsonPatchTestFailedException",
"message": "Expected null but found value 3 at /x"
}
],
Expand All @@ -43,4 +46,4 @@
"expected": null
}
]
}
}