com.jayway.jsonpath.matchers.WithoutJsonPath Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-path-assert Show documentation
Show all versions of json-path-assert Show documentation
A library to query and verify JSON
package com.jayway.jsonpath.matchers;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.JsonPathException;
import com.jayway.jsonpath.ReadContext;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeDiagnosingMatcher;
public class WithoutJsonPath extends TypeSafeDiagnosingMatcher {
private final JsonPath jsonPath;
public WithoutJsonPath(JsonPath jsonPath) {
this.jsonPath = jsonPath;
}
@Override
protected boolean matchesSafely(ReadContext actual, Description mismatchDescription) {
try {
Object value = actual.read(jsonPath);
mismatchDescription
.appendText(jsonPath.getPath())
.appendText(" was evaluated to ")
.appendValue(value);
return false;
} catch (JsonPathException e) {
return true;
}
}
@Override
public void describeTo(Description description) {
description.appendText("without json path ").appendValue(jsonPath.getPath());
}
}