Class LocalDateTimeMatchers


  • public abstract class LocalDateTimeMatchers
    extends Object
    Static factory for creating Matcher instances for comparing LocalDateTime instances
    Author:
    Stewart Bissett
    • Constructor Detail

      • LocalDateTimeMatchers

        public LocalDateTimeMatchers()
    • Method Detail

      • after

        public static TemporalMatcher<LocalDateTime> after​(LocalDateTime date)
        Creates a matcher that matches when the examined date is after the reference date

        For example:

         MatcherAssert.assertThat(myDate, LocalDateTimeMatchers.after(LocalDateTime.now()));
         
        Parameters:
        date - the reference date against which the examined date is checked
      • after

        public static TemporalMatcher<LocalDateTime> after​(int year,
                                                           Month month,
                                                           int dayOfMonth,
                                                           int hour,
                                                           int minute,
                                                           int second)
        Creates a matcher that matches when the examined date is after the end of the reference year

        For example:

         MatcherAssert.assertThat(myDate, LocalDateTimeMatchers.after(2012, Month.MAY, 12));
         
        Parameters:
        year - the year against which the examined date is checked
        month - the month against which the examined date is checked
        dayOfMonth - the day of the month against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
      • before

        public static TemporalMatcher<LocalDateTime> before​(LocalDateTime date)
        Creates a matcher that matches when the examined date is before the reference date

        For example:

         MatcherAssert.assertThat(myDate, LocalDateTimeMatchers.before(LocalDateTime.now()));
         
        Parameters:
        date - the reference date against which the examined date is checked
      • before

        public static TemporalMatcher<LocalDateTime> before​(int year,
                                                            Month month,
                                                            int dayOfMonth,
                                                            int hour,
                                                            int minute,
                                                            int second)
        Creates a matcher that matches when the examined date is before the end of the reference year

        For example:

         MatcherAssert.assertThat(myDate, LocalDateTimeMatchers.before(2012, Month.MAY, 12));
         
        Parameters:
        year - the year against which the examined date is checked
        month - the month against which the examined date is checked
        dayOfMonth - the day of the month against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
      • sameDay

        public static TemporalMatcher<LocalDateTime> sameDay​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same day of the year as the reference date

        For example:

         assertThat(myDate, sameDay(LocalDateTime.now()));
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isDay

        public static TemporalMatcher<LocalDateTime> isDay​(LocalDate date)
        Creates a matcher that matches when the examined date is on the same day of the year as the reference date

        For example:

         assertThat(myDate, sameDay(LocalDate.now()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isDay

        public static TemporalMatcher<LocalDateTime> isDay​(int year,
                                                           Month month,
                                                           int dayOfMonth)
        Creates a matcher that matches when the examined date is on the same day of the year as the reference date

        For example:

         assertThat(myDate, sameDay(2012, Month.JAN, 1))
         
        Parameters:
        dayOfMonth - the reference day of the month against which the examined date is checked
        month - the reference month against which the examined date is checked
        year - the reference year against which the examined date is checked
      • sameInstant

        public static TemporalMatcher<LocalDateTime> sameInstant​(LocalDateTime date)
        Creates a matcher that matches when the examined date is at the same instant as the reference date

        For example:

         assertThat(myDate, sameInstant(LocalDateTime.now()));
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isInstant

        public static TemporalMatcher<LocalDateTime> isInstant​(int year,
                                                               Month month,
                                                               int dayOfMonth,
                                                               int hour,
                                                               int minute,
                                                               int second,
                                                               int nanos)
        Creates a matcher that matches when the examined date is at the same specified instance down to the second

        For example:

         assertThat(myDate, sameInstant(2012, Month.JAN, 1, 3, 15, 0))
         
        Parameters:
        dayOfMonth - the reference day of the month against which the examined date is checked
        month - the reference month against which the examined date is checked
        year - the reference year against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
        nanos - the nanosecond of the second
      • sameOrBefore

        public static TemporalMatcher<LocalDateTime> sameOrBefore​(LocalDateTime date)
        Creates a matcher that matches when the examined date is at the same instant or before the reference date

        For example:

         assertThat(myDate, isSameOrBefore(new Date()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • sameOrBefore

        public static TemporalMatcher<LocalDateTime> sameOrBefore​(int year,
                                                                  Month month,
                                                                  int day,
                                                                  int hour,
                                                                  int minute,
                                                                  int second)
        Creates a matcher that matches when the examined date is on the same day or before the start of the reference date

        For example:

         assertThat(myDate, isSameOrBefore(2012, Months.MAY, 12));
         
        Parameters:
        year - the year against which the examined date is checked
        month - the month against which the examined date is checked
        day - the day of the month against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
      • sameOrAfter

        public static TemporalMatcher<LocalDateTime> sameOrAfter​(LocalDateTime date)
        Creates a matcher that matches when the examined date is at the same instant or after the reference date

        For example:

         assertThat(myDate, isSameOrAfter(new Date()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • sameOrAfter

        public static TemporalMatcher<LocalDateTime> sameOrAfter​(int year,
                                                                 Month month,
                                                                 int day,
                                                                 int hour,
                                                                 int minute,
                                                                 int second)
        Creates a matcher that matches when the examined date is on the same day or after the start of the reference date

        For example:

         assertThat(myDate, isSameOrAfter(2012, Months.MAY, 12));
         
        Parameters:
        year - the year against which the examined date is checked
        month - the month against which the examined date is checked
        day - the day of the month against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
      • sameMonthOfYear

        public static TemporalMatcher<LocalDateTime> sameMonthOfYear​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same month as the reference date

        For example:

         assertThat(myDate, sameMonth(new Date()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • sameDayOfMonth

        public static TemporalMatcher<LocalDateTime> sameDayOfMonth​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same day of the month as the reference date

        For example:

         assertThat(myDate, sameDayOfMonth(new Date()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isDayOfMonth

        public static TemporalMatcher<LocalDateTime> isDayOfMonth​(int dayOfMonth)
        Creates a matcher that matches when the examined date is on the expected day of the month

        For example:

         assertThat(myDate, isDayOfMonth(4))
         
        Parameters:
        dayOfMonth - the expected day of the month
      • sameYear

        public static TemporalMatcher<LocalDateTime> sameYear​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same year as the reference date

        For example:

         assertThat(myDate, sameYear(new Date()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isYear

        public static TemporalMatcher<LocalDateTime> isYear​(int year)
        Creates a matcher that matches when the examined date is on the same year as the reference year

        For example:

         assertThat(myDate, sameYear(2013))
         
        Parameters:
        year - the reference year against which the examined date is checked
      • within

        public static TemporalMatcher<LocalDateTime> within​(long period,
                                                            ChronoUnit unit,
                                                            LocalDateTime date)
        Creates a matcher that matches when the examined date is within a defined period the reference date

        For example:

         assertThat(myDate, within(10, TimeUnit.DAYS, Moments.today()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • within

        public static TemporalMatcher<LocalDateTime> within​(long period,
                                                            ChronoUnit unit,
                                                            int year,
                                                            Month month,
                                                            int dayofMonth,
                                                            int hour,
                                                            int minute,
                                                            int second,
                                                            int nanos)
        Creates a matcher that matches when the examined date is within a given period of the reference date

        For example:

         assertThat(myDate, within(5, TimeUnit.DAYS, 2012, Months.MAY, 12));
         
        Parameters:
        period - the timeunit interval the examined date should be with
        unit - the timeunit to define the length of the period
        year - the year against which the examined date is checked
        month - the month against which the examined date is checked
        dayofMonth - the day of the month against which the examined date is checked
        hour - the hour of the day
        minute - the minute of the hour
        second - the second of the minute
        nanos - the nanoseconds of the second
      • isYesterday

        public static TemporalMatcher<LocalDateTime> isYesterday()
        Creates a matcher that matches when the examined date is yesterday

        For example:

         assertThat(myDate, isToday());
         
      • isToday

        public static TemporalMatcher<LocalDateTime> isToday()
        Creates a matcher that matches when the examined date is today

        For example:

         assertThat(myDate, isToday());
         
      • isTomorrow

        public static TemporalMatcher<LocalDateTime> isTomorrow()
        Creates a matcher that matches when the examined date is tomorrow

        For example:

         assertThat(myDate, isTomorrow());
         
      • sameDayOfWeek

        public static TemporalMatcher<LocalDateTime> sameDayOfWeek​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same day of the week as the reference date

        For example:

         assertThat(myDate, sameDayOfWeek(LocalDateTime.now()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isDayOfWeek

        public static TemporalMatcher<LocalDateTime> isDayOfWeek​(DayOfWeek dayOfWeek)
        Creates a matcher that matches when the examined date is on a monday

        For example:

         assertThat(myDate, isMonday());
         
      • isDayOfWeek

        public static TemporalMatcher<LocalDateTime> isDayOfWeek​(DayOfWeek... daysOfWeek)
        Creates a matcher that matches when the examined date is on a monday

        For example:

         assertThat(myDate, isMonday());
         
      • isMonday

        public static TemporalMatcher<LocalDateTime> isMonday()
        Creates a matcher that matches when the examined date is on a monday

        For example:

         assertThat(myDate, isMonday());
         
      • isTuesday

        public static TemporalMatcher<LocalDateTime> isTuesday()
        Creates a matcher that matches when the examined date is on a tuesday

        For example:

         assertThat(myDate, isTuesday());
         
      • isWednesday

        public static TemporalMatcher<LocalDateTime> isWednesday()
        Creates a matcher that matches when the examined date is on a wednesday

        For example:

         assertThat(myDate, isWednesday());
         
      • isThursday

        public static TemporalMatcher<LocalDateTime> isThursday()
        Creates a matcher that matches when the examined date is on a thursday

        For example:

         assertThat(myDate, isThursday());
         
      • isFriday

        public static TemporalMatcher<LocalDateTime> isFriday()
        Creates a matcher that matches when the examined date is on a friday

        For example:

         assertThat(myDate, isFriday());
         
      • isSaturday

        public static TemporalMatcher<LocalDateTime> isSaturday()
        Creates a matcher that matches when the examined date is on a saturday

        For example:

         assertThat(myDate, isSaturday());
         
      • isSunday

        public static TemporalMatcher<LocalDateTime> isSunday()
        Creates a matcher that matches when the examined date is on a sunday

        For example:

         assertThat(myDate, isSunday());
         
      • isWeekday

        public static TemporalMatcher<LocalDateTime> isWeekday()
        Creates a matcher that matches when the examined date is on a weekday

        For example:

         assertThat(myDate, isWeekday());
         
      • isWeekend

        public static TemporalMatcher<LocalDateTime> isWeekend()
        Creates a matcher that matches when the examined date is on a weekend

        For example:

         assertThat(myDate, isWeekend());
         
      • isFirstDayOfMonth

        public static TemporalMatcher<LocalDateTime> isFirstDayOfMonth()
        Creates a matcher that matches when the examined date is on the first day of the month

        For example:

         assertThat(myDate, isFirstDayOfMonth());
         
      • isMinimum

        public static TemporalMatcher<LocalDateTime> isMinimum​(ChronoField field)
        Creates a matcher that matches when the examined date is on the maximum value of the given date part in its period

        For example:

         assertThat(myDate, isMaximumDayOfMonth(ChronoField.DAY_OF_MONTH));
         
        Parameters:
        field - the temporal field to check
      • isLastDayOfMonth

        public static TemporalMatcher<LocalDateTime> isLastDayOfMonth()
        Creates a matcher that matches when the examined date is on the first day of the month

        For example:

         assertThat(myDate, isFirstDayOfMonth());
         
      • isMaximum

        public static TemporalMatcher<LocalDateTime> isMaximum​(ChronoField field)
        Creates a matcher that matches when the examined date is on the maximum value of the given date part in its period

        For example:

         assertThat(myDate, isMaximum(ChronoField.DAY_OF_MONTH));
         
        Parameters:
        field - the temporal field to check
      • isMonth

        public static TemporalMatcher<LocalDateTime> isMonth​(Month month)
        Creates a matcher that matches when the examined date is in the expected month

        For example:

         assertThat(myDate, isMonth(Month.AUGUST));
         
      • isJanuary

        public static TemporalMatcher<LocalDateTime> isJanuary()
        Creates a matcher that matches when the examined date is in January

        For example:

         assertThat(myDate, isJanuary());
         
      • isFebruary

        public static TemporalMatcher<LocalDateTime> isFebruary()
        Creates a matcher that matches when the examined date is in February

        For example:

         assertThat(myDate, isFebruary());
         
      • isMarch

        public static TemporalMatcher<LocalDateTime> isMarch()
        Creates a matcher that matches when the examined date is in March

        For example:

         assertThat(myDate, isMarch());
         
      • isApril

        public static TemporalMatcher<LocalDateTime> isApril()
        Creates a matcher that matches when the examined date is in April

        For example:

         assertThat(myDate, isApril());
         
      • isMay

        public static TemporalMatcher<LocalDateTime> isMay()
        Creates a matcher that matches when the examined date is in May

        For example:

         assertThat(myDate, isMay());
         
      • isJune

        public static TemporalMatcher<LocalDateTime> isJune()
        Creates a matcher that matches when the examined date is in June

        For example:

         assertThat(myDate, isJune());
         
      • isJuly

        public static TemporalMatcher<LocalDateTime> isJuly()
        Creates a matcher that matches when the examined date is in July

        For example:

         assertThat(myDate, isJuly());
         
      • isAugust

        public static TemporalMatcher<LocalDateTime> isAugust()
        Creates a matcher that matches when the examined date is in August

        For example:

         assertThat(myDate, isAugust());
         
      • isSeptember

        public static TemporalMatcher<LocalDateTime> isSeptember()
        Creates a matcher that matches when the examined date is in September

        For example:

         assertThat(myDate, isSeptember());
         
      • isOctober

        public static TemporalMatcher<LocalDateTime> isOctober()
        Creates a matcher that matches when the examined date is in October

        For example:

         assertThat(myDate, isOctober());
         
      • isNovember

        public static TemporalMatcher<LocalDateTime> isNovember()
        Creates a matcher that matches when the examined date is in November

        For example:

         assertThat(myDate, isNovember());
         
      • isDecember

        public static TemporalMatcher<LocalDateTime> isDecember()
        Creates a matcher that matches when the examined date is in December

        For example:

         assertThat(myDate, isDecember());
         
      • isLeapYear

        public static TemporalMatcher<LocalDateTime> isLeapYear()
        Creates a matcher that matches when the examined date is a leap year

        For example:

         assertThat(myDate, isLeapYear());
         
      • isHour

        public static TemporalMatcher<LocalDateTime> isHour​(int hour)
        Creates a matcher that matches when the examined date is on the expected hour (0-23)

        For example:

         assertThat(myDate, isHour(12));
         
        Parameters:
        hour - the hour of the day (0-23)
      • sameHourOfDay

        public static TemporalMatcher<LocalDateTime> sameHourOfDay​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same hour as the reference date

        For example:

         assertThat(myDate, sameHourOfDay(LocalDateTime.now()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isMinute

        public static TemporalMatcher<LocalDateTime> isMinute​(int minute)
        Creates a matcher that matches when the examined date is on the expected minute (0-59)

        For example:

         assertThat(myDate, isMinute(12));
         
        Parameters:
        minute - the minute of the day (0-59)
      • sameMinuteOfHour

        public static TemporalMatcher<LocalDateTime> sameMinuteOfHour​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same minute as the reference date

        For example:

         assertThat(myDate, sameMinuteOfHour(LocalDateTime.now()))
         
        Parameters:
        date - the reference date against which the examined date is checked
      • isSecond

        public static TemporalMatcher<LocalDateTime> isSecond​(int second)
        Creates a matcher that matches when the examined date is on the expected second (0-59)

        For example:

         assertThat(myDate, isSecond(12));
         
        Parameters:
        second - the second of the day (0-59)
      • sameSecondOfMinute

        public static TemporalMatcher<LocalDateTime> sameSecondOfMinute​(LocalDateTime date)
        Creates a matcher that matches when the examined date is on the same second as the reference date

        For example:

         assertThat(myDate, sameSecondOfMinute(LocalDateTime.now()))
         
        Parameters:
        date - the reference date against which the examined date is checked