AssertJ的"usingComparatorForFields"如何工作? [英] How does AssertJ's `usingComparatorForFields` work?

查看:118
本文介绍了AssertJ的"usingComparatorForFields"如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用assertJ进行递归忽略给定字段的比较?

作为解决此问题的方法,我尝试为不希望比较器进行比较的字段装配比较器,并使其返回0.

As a work around the problem, I tried to rig the comparator for the field which I don't want the comparator to compare and made it return 0.

assertThat(service.postComment(12,234,comment)).usingComparatorForFields((a,b)->0,"startDate").isEqualToComparingFieldByFieldRecursively(commentReturned);

但是,我仍然遇到这个异常.

But, still I get this exception.

Path to difference:  <startDate>
- expected: <null>
- actual  : <2017-04-12 18:28:06.766>

作为旁注-我不想比较startDate,因为它使用旧版java.util.Date来检索当前日期,而旧版java.util.Date也比较毫秒.

As a sidenote - I don't want to compare startDate because it retrieves current date using legacy java.util.Date which compares milli seconds too.

usingComparatorForFields的工作方式.我什至用isEqualToComparingFieldByField而不是isEqualToComparingFieldByFieldRecursively尝试了它,错误仍然存​​在(在同一情况下.对于需要递归比较的情况,此操作将失败.)

How does it usingComparatorForFields work. I even tried it using isEqualToComparingFieldByField instead of isEqualToComparingFieldByFieldRecursively and the error persists (in the same case. This one fails for cases where recursive comparison is required.)

推荐答案

从我看来,这似乎是一个错误,您正在使用什么版本的AssertJ?

This looks like a bug from what I see, what version of AssertJ are you using ?

您可以通过简单的测试在 assertj-core 中创建问题吗?情况下重现错误?

Can you create an issue in assertj-core with a simple test case reproducing the error ?

这篇关于AssertJ的"usingComparatorForFields"如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆