Closed Proximator closed 11 years ago
Good suggestion.
You'd have to set some bounds on it though to avoid isFirstDayOfMonth(), isSecondDayOfMonth(), isThirdDayOfMonth(), etc. This would lead to a more general form of isDayOfMonth(dayOfMonth) but with some non-general for isFirstDayOfMonth(), isLastDayOfMonth().
There is some limited support on this line i.e. DateMatchers.sameWeekday(WeekDays.MONDAY) but this again could be transformed to isMonday(), isTuesday().
I'll also add isLeapYear().
I'll add matchers to support this pattern.
Regards
stewbis
The problem with sameWeekday(WeekDays.MONDAY) is that it takes an arguments. Hamcrest should have matchers that looks like english sentence to be more readable assertThat (date1, isMonday()); this format is far better
Regards
Perhaps, we can group all the related day matchers in DayMatchers (isMonday, isFraday,.., ) MonthMatchers (isJanuary, isFebrary,...,isFirstOfMonth, isLastOfMonth...) YearMatchers ( isLeapYear, ...) Then all these matchers in DateMatchers Like CoreMatchers/Matchers in Hamcrest, it regroups all the other matchers
I wasn't clear in my comment. I'll add on isMonday(), isTuesday(), etc.
It makes sense to have DayMatchers, MonthMatchers, YearMatchers as the implementation classes and DateMatchers delegates to it i.e. the same pattern followed in the other matchers.
Ok, that nice :+1:
Hi stewbis,
Is it worth to have HourMatchers, MinuteMatchers ? (to have something like: beforeHour, beforeMiday, afterMiday, ...) ?
MinuteMatchers would probably be going too far - I can't think of many test cases for isFirstMinuteOfHour() and if a developer really want to do that DateMatcher.sameMinute(1) would meet the test case but not as clean to read. HourMatchers perhaps, isPM(), isAM(),
I've also commit the DayMatchers. The mismatch description needs some sorting - but the DayMatcher support is added.
Changes have been released in version 0.9.3
So far, there is only matchers for 2 arguments (2 dates, actual and expected) But we can make assertions for the actual only, for example assertThat(date1, isFirstDayOfMonth()) assertThat(date1, isFirstDayOfWeek()) ... assertThat(date1, isLastDayOfMonth()) assertThat(date1, isLastDayOfWeek()) assertThat(date1, isLeapYear()) ....
Regards