This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Testing and the fly likes Matchers ignoring date or timestamp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » Testing
Bookmark "Matchers ignoring date or timestamp?" Watch "Matchers ignoring date or timestamp?" New topic

Matchers ignoring date or timestamp?

Nico Van Brandt
Ranch Hand

Joined: Mar 31, 2011
Posts: 66

Hi everyone,

I'm wondering; are there pre-made matchers in jUnit or hamcrest (or other libs) that allow to do an assertEquals while ignoring a Date or Timestamp object within the matched object?
I can't find any and it is hard to believe that people would not want to use such matchers...

Thanks a lot!


Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

You probably found this post:

can you work with any of those solutions?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

After thinking about this more and talking with my smarter co-worker, I realized that this isn't a junit problem, it is a problem with how you implemented equals on your value object. If you want two objects to be equal in spite of the date, then the equals (and hashcode) method must be overridden.
I agree. Here's the link:
subject: Matchers ignoring date or timestamp?
It's not a secret anymore!