简体   繁体   中英

AssertJ - Is there a more fluent way to extract/map values?

I have following test code

ObjectNode jsonObject = ..
assertThat(jsonObject.get("level")).isNotNull();
assertThat(jsonObject.get("level").get("object")).isNotNull();
assertThat(jsonObject.get("level").get("object").textValue()).isEqualTo("my value");

I would like to write this in a more fluent way such as

assertThat(jsonObject.get("level")).isNotNull()
    .extracting(jsonNode -> jsonNode.get("object"))
    .isNotNull()
    .extracting(JsonNode::asText)
    .isEqualTo("my value");

It does not seem that extracting() was designed for this. Is there any other more fluent way to write out initial test code?

我会认真尝试https://github.com/lukas-krecan/JsonUnit ,它被设计为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM