Patrik Helsing
9 years ago
6 changed files with 133 additions and 11 deletions
@ -0,0 +1,36 @@
|
||||
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; |
||||
|
||||
import static org.hamcrest.Matchers.empty; |
||||
|
||||
public class WithoutJsonPath extends TypeSafeDiagnosingMatcher<ReadContext> { |
||||
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 value == null || empty().matches(value); |
||||
} catch (JsonPathException e) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void describeTo(Description description) { |
||||
description.appendText("without json path ").appendValue(jsonPath.getPath()); |
||||
} |
||||
} |
Loading…
Reference in new issue