srnjak-testing-json

Testing utility for Json using javax.json

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.srnjak
ArtifactId

ArtifactId

srnjak-testing-json
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

srnjak-testing-json
Testing utility for Json using javax.json
Project URL

Project URL

https://github.com/srnjak/srnjak-testing-json
Source Code Management

Source Code Management

https://github.com/srnjak/srnjak-testing-json

Download srnjak-testing-json

How to add to project

<!-- https://jarcasting.com/artifacts/com.srnjak/srnjak-testing-json/ -->
<dependency>
    <groupId>com.srnjak</groupId>
    <artifactId>srnjak-testing-json</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.srnjak/srnjak-testing-json/
implementation 'com.srnjak:srnjak-testing-json:1.0.1'
// https://jarcasting.com/artifacts/com.srnjak/srnjak-testing-json/
implementation ("com.srnjak:srnjak-testing-json:1.0.1")
'com.srnjak:srnjak-testing-json:jar:1.0.1'
<dependency org="com.srnjak" name="srnjak-testing-json" rev="1.0.1">
  <artifact name="srnjak-testing-json" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.srnjak', module='srnjak-testing-json', version='1.0.1')
)
libraryDependencies += "com.srnjak" % "srnjak-testing-json" % "1.0.1"
[com.srnjak/srnjak-testing-json "1.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.5.2
org.glassfish : javax.json jar 1.1.4

provided (1)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1.4

Project Modules

There are no modules declared in this project.

Srnjak JSON test

Java utility for writing JSON tests. It supports standard json representations from javax.json package as well as string representation or any combinations between them.

Supports testing framework JUnit 5.

Build

Use maven for build the source:

mvn clean install

Usage

Released version of library is available at Maven Central. Include it into your project's pom.xml as a test dependency using the following coordinates (do not forget to specify the desired version):

<dependency>
    <groupId>com.srnjak</groupId>
    <artifactId>srnjak-testing-json</artifactId>
    <version>1.0.1</version>
    <scope>test</scope>
</dependency>

Call desired method from com.srnjak.testing.json.AssertJson class. It supports the following asserts:

assertEquals(expected, actual)
assertNotEquals(unexpected, actual)
assertContains(expectedElement, actualArray)
assertNotContains(unexpectedElement, actualArray)
assertContainsAll(expectedElements, actualArray)
assertContainsAny(expectedElements, actualArray)
assertContainsNone(unexpectedElements, actualArray)
assertContainsProperty(expectedValue, path, actual)
assertNotContainsProperty(unexpectedValue, path, actual)

Test example

@Test
public void jsonTest() {
    
    JsonObject expected = Json.createObjectBuilder()
        .add("name", "John Doe")
        .add("age", 30)
        .build();
        
    JsonObject actual = getActualJson(); // get it from service under test
    
    AssertJson.assertEquals(expected, actual);
}

Versions

Version
1.0.1
1.0.0