eXparity / hamcrest-date

A Java library which provides a suite hamcrest matchers for matching dates, times, and moments in time
BSD 3-Clause "New" or "Revised" License
70 stars 11 forks source link

sameInstant matcher doesn't handle null #19

Open jacobg opened 8 years ago

jacobg commented 8 years ago

Current behavior when calling sameInstant with a null date is NullPointerException:

java.lang.NullPointerException
    at org.exparity.hamcrest.date.core.wrapper.DateWrapper.<init>(DateWrapper.java:30)
    at org.exparity.hamcrest.date.DateMatchers.sameInstant(DateMatchers.java:557)

It'd be nice if the matcher constructor did not have that exception, and would just return false on the matchesSafely call. That would allow a composite match like this:

assertThat(date, either(sameInstant(otherDate)).or(allOf(nullValue(), is(otherDate))));

stewbis commented 8 years ago

Hi, I agree, it should definately not throw a NullPointerException but return false. I'll apply a fix which will be included in the next release

jacobg commented 8 years ago

Thanks!

stewbis commented 8 years ago

Hi, Just to keep you up to date. Many of the calls can suffer NullPointerException if the expectation is null so i'm setting up tests and applying the fixes for all. It may take a little while to fix them all up. Will reply on this post once they're resolved. Thanks, Stewart