Add hasJsonPath/doesNotHaveJsonPath assertion options
Issue: SPR-16339
This commit is contained in:
@@ -20,7 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JsonPathExpectationsHelper}.
|
||||
@@ -217,6 +217,54 @@ public class JsonPathExpectationsHelperTests {
|
||||
new JsonPathExpectationsHelper(expression).assertValueIsNotEmpty(CONTENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasJsonPath() {
|
||||
new JsonPathExpectationsHelper("$.abc").hasJsonPath("{\"abc\": \"123\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasJsonPathWithNull() {
|
||||
new JsonPathExpectationsHelper("$.abc").hasJsonPath("{\"abc\": null}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasJsonPathForIndefinatePathWithResults() {
|
||||
new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Bart')]").hasJsonPath(SIMPSONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasJsonPathForIndefinatePathWithEmptyResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Dilbert')]";
|
||||
exception.expect(AssertionError.class);
|
||||
exception.expectMessage("No values for JSON path \"" + expression + "\"");
|
||||
new JsonPathExpectationsHelper(expression).hasJsonPath(SIMPSONS);
|
||||
}
|
||||
|
||||
@Test // SPR-16339
|
||||
public void doesNotHaveJsonPath() {
|
||||
new JsonPathExpectationsHelper("$.abc").doesNotHaveJsonPath("{}");
|
||||
}
|
||||
|
||||
@Test // SPR-16339
|
||||
public void doesNotHaveJsonPathWithNull() {
|
||||
exception.expect(AssertionError.class);
|
||||
new JsonPathExpectationsHelper("$.abc").doesNotHaveJsonPath("{\"abc\": null}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveJsonPathForIndefinatePathWithEmptyResults() {
|
||||
new JsonPathExpectationsHelper("$.familyMembers[?(@.name == 'Dilbert')]").doesNotHaveJsonPath(SIMPSONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotHaveEmptyPathForIndefinatePathWithResults() {
|
||||
String expression = "$.familyMembers[?(@.name == 'Bart')]";
|
||||
exception.expect(AssertionError.class);
|
||||
exception.expectMessage("Expected no values at JSON path \"" + expression + "\" " +
|
||||
"but found: [{\"name\":\"Bart\"}]");
|
||||
new JsonPathExpectationsHelper(expression).doesNotHaveJsonPath(SIMPSONS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertValue() throws Exception {
|
||||
new JsonPathExpectationsHelper("$.num").assertValue(CONTENT, 5);
|
||||
|
||||
Reference in New Issue
Block a user