You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
78 lines
2.5 KiB
14 years ago
|
package com.jayway.jsonassert;
|
||
14 years ago
|
|
||
|
import org.hamcrest.Matcher;
|
||
|
|
||
|
/**
|
||
14 years ago
|
* Created by IntelliJ IDEA.
|
||
|
* User: kallestenflo
|
||
|
* Date: 1/24/11
|
||
|
* Time: 9:22 PM
|
||
14 years ago
|
*/
|
||
14 years ago
|
public interface JSONAsserter {
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
14 years ago
|
* Gives access to the {@link JSONReader} used to base the assertions on
|
||
14 years ago
|
*
|
||
14 years ago
|
* @return the underlying reader
|
||
14 years ago
|
*/
|
||
14 years ago
|
JSONReader reader();
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Asserts that object specified by path satisfies the condition specified by matcher.
|
||
|
* If not, an AssertionError is thrown with information about the matcher
|
||
|
* and failing value. Example:
|
||
|
* <p/>
|
||
|
* <code>
|
||
|
* with(json).assertThat("items[0].name", equalTo("Bobby"))
|
||
|
* .assertThat("items[0].age" , equalTo(24L))
|
||
|
* </code>
|
||
|
*
|
||
|
* @param path the json path specifying the value being compared
|
||
|
* @param matcher an expression, built of Matchers, specifying allowed values
|
||
|
* @param <T> the static type accepted by the matcher
|
||
|
* @return this to allow fluent assertion chains
|
||
|
*/
|
||
14 years ago
|
<T> JSONAsserter assertThat(String path, Matcher<T> matcher);
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Asserts that object specified by path is equal to the expected value.
|
||
|
* If they are not, an AssertionError is thrown with the given message.
|
||
|
*
|
||
|
* @param path the json path specifying the value being compared
|
||
|
* @param expected the expected value
|
||
|
* @param <T> the static type that should be returned by the path
|
||
|
* @return this to allow fluent assertion chains
|
||
|
*/
|
||
14 years ago
|
<T> JSONAsserter assertEquals(String path, T expected);
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Asserts that object specified by path is null. If it is not, an AssertionError
|
||
|
* is thrown with the given message.
|
||
|
*
|
||
|
* @param path the json path specifying the value that should be null
|
||
|
* @return this to allow fluent assertion chains
|
||
|
*/
|
||
14 years ago
|
JSONAsserter assertNull(String path);
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Asserts that object specified by path is NOT null. If it is, an AssertionError
|
||
|
* is thrown with the given message.
|
||
|
*
|
||
|
* @param path the json path specifying the value that should be NOT null
|
||
|
* @return this to allow fluent assertion chains
|
||
|
*/
|
||
14 years ago
|
<T> JSONAsserter assertNotNull(String path);
|
||
14 years ago
|
|
||
14 years ago
|
/**
|
||
|
* Syntactic sugar to allow chaining assertions with a separating and() statement
|
||
|
* <p/>
|
||
|
* <p/>
|
||
|
* <code>
|
||
|
* with(json).assertThat("firstName", is(equalTo("Bobby"))).and().assertThat("lastName", is(equalTo("Ewing")))
|
||
|
* </code>
|
||
|
*
|
||
|
* @return this to allow fluent assertion chains
|
||
|
*/
|
||
14 years ago
|
JSONAsserter and();
|
||
14 years ago
|
}
|