Skip to content

Commit

Permalink
Touple extracting switches to pure AssertJ
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Apr 2, 2022
1 parent 76bc2d1 commit b199fb9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
import net.javacrumbs.jsonunit.core.internal.Diff;
import net.javacrumbs.jsonunit.core.internal.Path;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractListAssert;
import org.assertj.core.api.FactoryBasedNavigableListAssert;
import org.assertj.core.api.InstanceOfAssertFactory;
import org.assertj.core.api.ListAssert;
import org.assertj.core.api.ObjectAssert;
import org.assertj.core.error.BasicErrorMessageFactory;
import org.assertj.core.groups.Tuple;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -113,4 +117,16 @@ protected JsonListAssert newAbstractIterableAssert(Iterable<?> iterable) {
private Diff createDiff(Object other) {
return Diff.create(other, wrapDeserializedObject(actual), "fullJson", path, configuration);
}

@Override
public AbstractListAssert<?, List<? extends Tuple>, Tuple, ObjectAssert<Tuple>> extracting(String... propertiesOrFields) {
return toPureAssertJ().extracting(propertiesOrFields);
}

/**
* Drops all Json related comparators and switches to pure AssertJ assert.
*/
private ListAssert<Object> toPureAssertJ() {
return new ListAssert<>(actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down Expand Up @@ -769,6 +770,17 @@ protected void shouldFailOnTrainingToken() {
assertThatThrownBy(() -> assertThatJson("{\"test\":{}} SOME GARBAGE").isEqualTo("{\"test\": {}}"));
}

@Test
void arrayExtracting() {
assertThatJson("[\n" +
" {\"id\": 1, \"name\":\"Aaron\"},\n" +
" {\"id\": 2, \"name\":\"Paul\"}\n" +
" ]")
.isArray()
.extracting("id", "name")
.contains(tuple(valueOf(1), "Aaron"), tuple(valueOf(2), "Paul"));
}

@Test
void shouldAssertStringNumber() {
assertThatJson("{\"a\":\"1\"}").node("a").asNumber().isEqualByComparingTo("1");
Expand Down

0 comments on commit b199fb9

Please sign in to comment.