AssertJ中的filteredOn在assertk中有什么等价物?
创始人
2024-09-20 16:00:43
0

assertk 提供了枚举类 KFunction,可以使用该类的属性来获取对象列表中指定字段的属性值并进行断言。举个例子,假设现在有一个 Book 类,包含 title 和 author 两个属性,我们要对 title 进行断言。

在 AssertJ 中,可以使用 filteredOn 方法:

List books = Arrays.asList(
    new Book("The Lord of the Rings", "J. R. R. Tolkien"),
    new Book("The Hobbit", "J. R. R. Tolkien"),
    new Book("Harry Potter and the Philosopher's Stone", "J. K. Rowling")
);

assertThat(books).filteredOn(book -> book.getAuthor().equals("J. R. R. Tolkien"))
                  .extracting(Book::getTitle).containsOnly("The Lord of the Rings", "The Hobbit");

在 assertk 中,可以使用枚举类 KFunction:

val books = listOf(
    Book("The Lord of the Rings", "J. R. R. Tolkien"),
    Book("The Hobbit", "J. R. R. Tolkien"),
    Book("Harry Potter and the Philosopher's Stone", "J. K. Rowling")
)

assertThat(books).hasSize(3)
                 .extracting { it[KFunction(Book::author)] } // 获取 Book 列表中 author 属性的值
                 .containsOnly("J. R. R. Tolkien", "J. R. R. Tolkien", "J. K. Rowling")

在上面的例子中,我们可以使用 KFunction(Book::author) 获取 Book 类中 author 属性的属性值,并确保它们都被包含在返回的列表中。

相关内容

热门资讯

9分钟了解!wepoker代打... 9分钟了解!wepoker代打辅助机器人,wepoker透视破解版,其实是有挂(有挂猫腻)1、辅助器...
最新技巧!wepoker有没有... 最新技巧!wepoker有没有辅助,聚星ai辅助工具激活码,竟然是真的有挂(有挂功能)1、公共底牌简...
程序员教你!werplan透视... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
记者爆料!云扑克有透视吗,po... 记者爆料!云扑克有透视吗,pokemmo脚本,都是是真的有挂(有挂教程)1、游戏颠覆性的策略玩法,独...
揭秘真相!德普之星有辅助软件吗... 揭秘真相!德普之星有辅助软件吗,steampokermaster辅助,竟然是有挂(果真有挂)1、下载...
热点推荐!约局吧游戏挂,we-... 热点推荐!约局吧游戏挂,we-poker辅助,其实存在有挂(今日头条)1、让任何用户在无需安装教程第...
技术分享!aapoker插件,... 技术分享!aapoker插件,hhpoker辅助挂,一贯是有挂(有挂辅助)1、破解器简单,机器人操作...
热点推荐!aapoker俱乐部... 热点推荐!aapoker俱乐部靠谱吗,aapoker透视脚本,切实真的是有挂(有挂细节)1、有没有辅...
技巧知识分享!wepoker能... 技巧知识分享!wepoker能不能透视,wepoker怎么看牌型,一直是有挂(发现有挂)脚本下载中分...
一分钟了解!wepoker手机... 一分钟了解!wepoker手机插件,hhpoker德州透视挂,切实是真的有挂(有挂教程)亲,关键说明...