Reputation: 4177
I am trying to print and assert addressLine1 and postcode value from the JSON map object using assertJ but facing issues while asserting.
{
"Region": {
"Test": {
"address": {
"addressLine1": "addressLine1",
"addressLine2": "addressLine2",
"otherDetails": {
"postcode": "LS1 4HR",
"country": "United Kingdom"
}
}
}
}
}
I have converted jabove json to Map<String, Object> jsonAsMap and tried below:
assertThat(jsonAsMap)
.isNotNull()
.isNotEmpty()
.hasEntrySatisfying("Region", Region -> assertThat(Region).hasFieldOrProperty("Test").hasFieldOrProperty("address") )
.containsEntry("addressLine1","addressLine1");
Upvotes: 0
Views: 1122
Reputation: 7066
I recommend using https://github.com/lukas-krecan/JsonUnit for JSON assertions (or any other JSON assertions library), you will get much better features than AssertJ which does not know JSON.
Upvotes: 1