Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Matchers ignoring date or timestamp?  RSS feed

 
Nico Van Brandt
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Nico
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably found this post:
http://stackoverflow.com/questions/1671001/compare-date-objects-with-different-levels-of-precision

can you work with any of those solutions?
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!