Skip to content

olenagerasimova/matchers-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matchers-json

Hamcrest matchers for json objects

EO principles respected here DevOps By Rultor.com

Bintray Build Status Build status PDD status License Test Coverage

Motivation

This library helps to achieve single statement unit test rule, when testing JSON objects.

Download

To use it add maven dependency to your pom.xml:

<dependency>
  <groupId>com.g4s8</groupId>
  <artifactId>matchers-json</artifactId>
</dependency>

last version is: Bintray

Usage

You can find examples in src/test files.

To match a field in JSON object use JsonHas:

MatcherAssert.assertThat(
    Json.createObjectBuilder()
        .add(
            "foo",
            Json.createObjectBuilder()
              .add("bar", 42)
              .build()
        ).build(),
    new JsonHas(
        "foo",
        new JsonHas(
            "bar",
            new JsonValueIs(42)
        )
    )
);

To match json value use JsonValueIs:

  • for strings: new JsonValueIs("some string")
  • for numbers: new JsonValueIs(100)
  • for booleans: new JsonValueIs(true)
  • for json-null: JsonValueIs.NULL

To match JSON array items use JsonContains (not implemented yet: g4s8#2)

About

Hamcrest matchers for JSON objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%