How does AssertJ's `usingComparatorForFields`

2019-09-14 18:46发布

Related to How to compare recursively ignoring given fields using assertJ?

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>

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.

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.)

1条回答
来,给爷笑一个
2楼-- · 2019-09-14 19:03

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

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

查看更多
登录 后发表回答