Skip to content

Commit

Permalink
Rename JsonUnit asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Nov 15, 2024
1 parent 348dab7 commit 34f78fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@

public final class JsonAssertions {

/**
* Allows to move from standard AssertJ asserts to JsonUnit. For example
* <code>
* assertThat(resp)
* .hasFieldOrPropertyWithValue("trackingId", "abcd-0001") //<- Assertj API
* .extracting("json").asInstanceOf(JSON)
* .isObject().containsEntry("foo", "bar"); // <- JsonUnit API
* </code>
*/
public static final InstanceOfAssertFactory<Object, ConfigurableJsonAssert> JSON =
new InstanceOfAssertFactory<>(Object.class, jsonUnitJson());

static {
Assertions.useRepresentation(new JsonRepresentation());
}
Expand Down Expand Up @@ -83,29 +95,16 @@ public static Object value(Object input) {
* assertThat(mvc.get().uri("/sample"))
* .hasStatusOk()
* .bodyJson()
* .convertTo(jsonUnitAssert())
* .convertTo(jsonUnitJson())
* .inPath("result.array") <-- JsonUnit assert
* .isArray()
* .containsExactly(1, 2, 3);
* </code>
*/
public static AssertFactory<Object, ConfigurableJsonAssert> jsonUnitAssert() {
public static AssertFactory<Object, ConfigurableJsonAssert> jsonUnitJson() {
return new JsonUnitAssertFactory();
}

/**
* Allows to move from standard AssertJ asserts to JsonUnit. For example
* <code>
* assertThat(resp)
* .hasFieldOrPropertyWithValue("trackingId", "abcd-0001") //<- Assertj API
* .extracting("json").asInstanceOf(jsonUnitJson())
* .isObject().containsEntry("foo", "bar"); // <- JsonUnit API
* </code>
*/
public static InstanceOfAssertFactory<Object, ConfigurableJsonAssert> jsonUnitJson() {
return new InstanceOfAssertFactory<>(Object.class, jsonUnitAssert());
}

@FunctionalInterface
public interface JsonAssertionCallback {
void doAssert(@NotNull ConfigurableJsonAssert assertion);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.javacrumbs.jsonunit.spring.testit;

import static java.util.Collections.singleton;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.jsonUnitAssert;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.jsonUnitJson;
import static net.javacrumbs.jsonunit.spring.JsonUnitJsonComparator.comparator;
import static net.javacrumbs.jsonunit.spring.testit.demo.ExampleController.CORRECT_JSON;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
Expand Down Expand Up @@ -30,7 +30,7 @@ void shouldUseConvertToJAckson() {
assertThat(mvc.get().uri("/sample"))
.hasStatusOk()
.bodyJson()
.convertTo(jsonUnitAssert())
.convertTo(jsonUnitJson())
.inPath("result.array")
.isArray()
.containsExactly(1, 2, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.JSON;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.jsonUnitJson;
import static net.javacrumbs.jsonunit.assertj.JsonAssertions.value;
import static net.javacrumbs.jsonunit.core.ConfigurationWhen.path;
import static net.javacrumbs.jsonunit.core.ConfigurationWhen.paths;
Expand Down Expand Up @@ -2248,7 +2248,7 @@ record DummyResponse(String trackingId, String json) {}
assertThat(resp)
.hasFieldOrPropertyWithValue("trackingId", "abcd-0001") // <- Assertj API
.extracting("json")
.asInstanceOf(jsonUnitJson())
.asInstanceOf(JSON)
.isObject()
.containsEntry("foo", "bar"); // <- JsonUnit API
}
Expand Down

0 comments on commit 34f78fd

Please sign in to comment.