com.jayway.jsonassert.impl
Class JsonAsserterImpl

java.lang.Object
  extended by com.jayway.jsonassert.impl.JsonAsserterImpl
All Implemented Interfaces:
JsonAsserter

public class JsonAsserterImpl
extends java.lang.Object
implements JsonAsserter

User: kalle stenflo Date: 1/21/11 Time: 3:43 PM


Constructor Summary
JsonAsserterImpl(java.lang.Object jsonObject)
          Instantiates a new JSONAsserter
 
Method Summary
 JsonAsserter and()
          Syntactic sugar to allow chaining assertions with a separating and() statement

with(json).assertThat("firstName", is(equalTo("Bobby"))).and().assertThat("lastName", is(equalTo("Ewing")))

<T> JsonAsserter
assertEquals(java.lang.String path, T expected)
          Asserts that object specified by path is equal to the expected value.
 JsonAsserter assertNotDefined(java.lang.String path)
          Checks that a path is not defined within a document.
<T> JsonAsserter
assertNotNull(java.lang.String path)
          Asserts that object specified by path is NOT null.
 JsonAsserter assertNull(java.lang.String path)
          Asserts that object specified by path is null.
<T> JsonAsserter
assertThat(java.lang.String path, org.hamcrest.Matcher<T> matcher)
          Asserts that object specified by path satisfies the condition specified by matcher.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonAsserterImpl

public JsonAsserterImpl(java.lang.Object jsonObject)
Instantiates a new JSONAsserter

Parameters:
jsonObject - the object to make asserts on
Method Detail

assertThat

public <T> JsonAsserter assertThat(java.lang.String path,
                                   org.hamcrest.Matcher<T> matcher)
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:

with(json).assertThat("items[0].name", equalTo("Bobby")) .assertThat("items[0].age" , equalTo(24L))

Specified by:
assertThat in interface JsonAsserter
Type Parameters:
T - the static type accepted by the matcher
Parameters:
path - the json path specifying the value being compared
matcher - an expression, built of Matchers, specifying allowed values
Returns:
this to allow fluent assertion chains

assertEquals

public <T> JsonAsserter assertEquals(java.lang.String path,
                                     T expected)
Asserts that object specified by path is equal to the expected value. If they are not, an AssertionError is thrown with the given message.

Specified by:
assertEquals in interface JsonAsserter
Type Parameters:
T - the static type that should be returned by the path
Parameters:
path - the json path specifying the value being compared
expected - the expected value
Returns:
this to allow fluent assertion chains

assertNotDefined

public JsonAsserter assertNotDefined(java.lang.String path)
Checks that a path is not defined within a document. If the document contains the given path, an AssertionError is thrown

Specified by:
assertNotDefined in interface JsonAsserter
Parameters:
path - the path to make sure not exists
Returns:
this

assertNull

public JsonAsserter assertNull(java.lang.String path)
Asserts that object specified by path is null. If it is not, an AssertionError is thrown with the given message.

Specified by:
assertNull in interface JsonAsserter
Parameters:
path - the json path specifying the value that should be null
Returns:
this to allow fluent assertion chains

assertNotNull

public <T> JsonAsserter assertNotNull(java.lang.String path)
Asserts that object specified by path is NOT null. If it is, an AssertionError is thrown with the given message.

Specified by:
assertNotNull in interface JsonAsserter
Parameters:
path - the json path specifying the value that should be NOT null
Returns:
this to allow fluent assertion chains

and

public JsonAsserter and()
Syntactic sugar to allow chaining assertions with a separating and() statement

with(json).assertThat("firstName", is(equalTo("Bobby"))).and().assertThat("lastName", is(equalTo("Ewing")))

Specified by:
and in interface JsonAsserter
Returns:
this to allow fluent assertion chains


Copyright © 2011-2012. All Rights Reserved.