aspose file tools*
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
Author

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!

Nico


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:
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

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Matchers ignoring date or timestamp?