diff --git a/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonListAssert.java b/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonListAssert.java index 3a7c9c0ea..8963d1041 100644 --- a/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonListAssert.java +++ b/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonListAssert.java @@ -27,12 +27,12 @@ import static net.javacrumbs.jsonunit.core.internal.JsonUtils.wrapDeserializedObject; -public class JsonListAssert extends FactoryBasedNavigableListAssert, Object, JsonObjectAssert> { +public class JsonListAssert extends FactoryBasedNavigableListAssert, Object, JsonAssert> { private final Configuration configuration; private final Path path; JsonListAssert(List actual, Path path, Configuration configuration) { - super(actual, JsonListAssert.class, t -> new JsonObjectAssert(t, path, configuration)); + super(actual, JsonListAssert.class, t -> new JsonAssert(path, configuration, t)); this.path = path; this.configuration = configuration; usingComparator(new JsonComparator(configuration, path, true)); diff --git a/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonObjectAssert.java b/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonObjectAssert.java deleted file mode 100644 index 678cdc152..000000000 --- a/json-unit-assertj/src/main/java/net/javacrumbs/jsonunit/assertj/JsonObjectAssert.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2009-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.javacrumbs.jsonunit.assertj; - -import net.javacrumbs.jsonunit.core.Configuration; -import net.javacrumbs.jsonunit.core.internal.Diff; -import net.javacrumbs.jsonunit.core.internal.Path; -import org.assertj.core.api.AbstractAssert; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class JsonObjectAssert extends AbstractAssert { - private final Configuration configuration; - private final Path path; - - JsonObjectAssert(Object actual, Path path, Configuration configuration) { - super(actual, JsonObjectAssert.class); - this.path = path; - this.configuration = configuration; - usingComparator(new JsonComparator(configuration, path.asPrefix(), true)); - } - - @Override - @NotNull - public JsonObjectAssert isEqualTo(@Nullable Object expected) { - return compare(expected, configuration); - } - - @NotNull - private UnsupportedOperationException unsupportedOperation() { - return new UnsupportedOperationException("Operation not supported for JSON documents"); - } - - @NotNull - private JsonObjectAssert compare(@Nullable Object other, @NotNull Configuration configuration) { - describedAs(null); - Diff diff = Diff.create(other, actual, "fullJson", path, configuration); - diff.failIfDifferent(); - return this; - } -} diff --git a/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java b/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java index 3f86045fe..7715c94b7 100644 --- a/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java +++ b/tests/test-base/src/main/java/net/javacrumbs/jsonunit/test/base/AbstractAssertJTest.java @@ -1630,6 +1630,21 @@ void testArrayBug() { .isEqualTo(json("{\"value\": \"1\", \"title\": \"Entity\", \"info\": \"Entity info\"}")); } + @Test + void testArrayNode() { + assertThatJson("[\n" + + " {\"value\": \"1\", \"title\": \"Entity\", \"info\": \"Entity info\"},\n" + + " {\"value\": \"2\", \"title\": \"Column\", \"info\": \"Column info\"},\n" + + " {\"value\": \"3\", \"title\": \"Table\", \"info\": \"Table info\"},\n" + + " {\"value\": \"4\", \"title\": \"Schema\", \"info\": \"Schema info\"}\n" + + " ]") + .inPath("$[?(@.value =='1')]") + .isArray().first() + .node("title") + .isString() + .isEqualTo("Entity"); + } + @Test void testInnerString() { String json = "{\"myNode\":{\"inner\":\"foo\"}}";