Skip to content

Commit

Permalink
#474 Fix JsonListAssert.elments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Feb 15, 2022
1 parent 80815bb commit 5f946bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -26,6 +26,7 @@
import java.util.List;

import static net.javacrumbs.jsonunit.core.internal.JsonUtils.wrapDeserializedObject;
import static org.assertj.core.util.Lists.newArrayList;

public class JsonListAssert extends FactoryBasedNavigableListAssert<JsonListAssert, List<?>, Object, JsonAssert> {
private final Configuration configuration;
Expand Down Expand Up @@ -59,6 +60,11 @@ public JsonListAssert isNotEqualTo(@Nullable Object other) {
return this;
}

@Override
protected JsonListAssert newAbstractIterableAssert(Iterable<?> iterable) {
return new JsonListAssert(newArrayList(iterable), path, configuration);
}

@NotNull
private Diff createDiff(Object other) {
return Diff.create(other, wrapDeserializedObject(actual), "fullJson", path, configuration);
Expand Down
Expand Up @@ -1651,6 +1651,17 @@ void assertSame() {
assertThatJson(s).isEqualTo(s);
}

@Test
void testArrayElements() {
String json = "[ [ \"a\", \"b\", \"c\", \"d\","
+ " \"e\", \"f\", \"g\", \"h\", \"i\" ] ]";

assertThatJson(json).inPath("$.[0]")
.isArray()
.elements(3 /* d */, 4 /* e */, 5 /* f */ , 6 /* g */, 7 /* h */, 8 /* i */ )
.containsExactly("d", "e", "f", "g", "h", "i");
}

@Test
void testInnerString() {
String json = "{\"myNode\":{\"inner\":\"foo\"}}";
Expand Down

0 comments on commit 5f946bd

Please sign in to comment.