How does AssertJ's `usingComparatorForFields` work?

爱⌒轻易说出口 提交于 2019-12-12 01:59:09

问题


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:


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 ?



来源:https://stackoverflow.com/questions/43370317/how-does-assertjs-usingcomparatorforfields-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!