How does AssertJ's `usingComparatorForFields` work?
Asked Answered
Y

1

0

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

Yarak answered 12/4, 2017 at 13:1 Comment(0)
E
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 ?

Extract answered 12/4, 2017 at 22:18 Comment(2)
I'm using 3.6.2Yarak
Created the issue. #973Yarak

© 2022 - 2024 — McMap. All rights reserved.