0

In my case I need to request the set of names from two different systems and verify they are equal (regardless order). Most probably I don't understand smth, but this code works fine:

assertThat(asList(assertThat(firstJSON)
    .flatExtracting("innerObject")
    .extracting("name")).stream().map(Object::toString).collect(Collectors.toList()))
    .containsExactlyElementsOf(
            asList(assertThat(secondJSON)
                    .flatExtracting("innerObject")
                    .extracting("name")).stream().map(Object::toString).collect(Collectors.toList()));

, but it looks really ugly and I want something like this:

assertThat(firstJSON)
    .flatExtracting("innerObject")
    .extracting("name")
    .containsExactlyElementsOf(
            assertThat(secondJSON)
                    .flatExtracting("innerObject")
                    .extracting("name"));

I've tried many functions like isSubsetOf() or containsOnly(), also I tried putting casting here and there but always catching some exception/error.

How do I compare them?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
boringMax
  • 1
  • 2
  • It should really be `assertThat(getNamesOutOf(firstJSON)).isEqualTo(getNamesOutOf(secondJSON))`. We could help implementing `getNamesOutOf()` is we knew the type and structure of firstJSON and secondJSON. – JB Nizet May 14 '17 at 16:57

1 Answers1

0

At this point I would consider using https://github.com/lukas-krecan/JsonUnit instead of AssertJ, it provides nice navigation features to assert subsection of your JSON data.

Joel Costigliola
  • 6,308
  • 27
  • 35