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?
在这一点上,我将考虑使用https://github.com/lukas-krecan/JsonUnit代替AssertJ,它提供了不错的导航功能来断言JSON数据的各个部分。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.