Top Description Fields Constructors Methods
org.assertj.core.internal

public Class Dates

extends Object
Class Inheritance
Static Imports
java.util.Objects.requireNonNull, org.assertj.core.error.ShouldBeAfter.shouldBeAfter, .ShouldBeAfterOrEqualTo.shouldBeAfterOrEqualTo, .ShouldBeAfterYear.shouldBeAfterYear, .ShouldBeBefore.shouldBeBefore, .ShouldBeBeforeOrEqualTo.shouldBeBeforeOrEqualTo, .ShouldBeBeforeYear.shouldBeBeforeYear, .ShouldBeBetween.shouldBeBetween, .ShouldBeCloseTo.shouldBeCloseTo, .ShouldBeInSameDay.shouldBeInSameDay, .ShouldBeInSameHour.shouldBeInSameHour, .ShouldBeInSameHourWindow.shouldBeInSameHourWindow, .ShouldBeInSameMinute.shouldBeInSameMinute, .ShouldBeInSameMinuteWindow.shouldBeInSameMinuteWindow, .ShouldBeInSameMonth.shouldBeInSameMonth, .ShouldBeInSameSecond.shouldBeInSameSecond, .ShouldBeInSameSecondWindow.shouldBeInSameSecondWindow, .ShouldBeInSameYear.shouldBeInSameYear, .ShouldBeInTheFuture.shouldBeInTheFuture, .ShouldBeInThePast.shouldBeInThePast, .ShouldBeToday.shouldBeToday, .ShouldHaveDateField.shouldHaveDateField, .ShouldHaveSameTime.shouldHaveSameTime, .ShouldHaveTime.shouldHaveTime, .ShouldNotBeBetween.shouldNotBeBetween, org.assertj.core.util.DateUtil.dayOfMonthOf, .DateUtil.dayOfWeekOf, .DateUtil.hourOfDayOf, .DateUtil.millisecondOf, .DateUtil.minuteOf, .DateUtil.monthOf, .DateUtil.now, .DateUtil.secondOf, .DateUtil.timeDifference, .DateUtil.truncateTime, .DateUtil.yearOf

Reusable assertions for Dates.
Authors
Joel Costigliola, William Delanoue

Field Summary

Modifier and TypeField and Description
private final ComparisonStrategy
pack-priv Failures
private static final Dates

Constructor Summary

AccessConstructor and Description
pack-priv
public
Dates(ComparisonStrategy comparisonStrategy)

Method Summary

Modifier and TypeMethod and Description
private boolean
actualIsBetweenGivenPeriod(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd)

private boolean

Returns:

true if the actual Date is equal to the given one according to underlying comparisonStrategy, false otherwise.
areEqual
(Date
the actual date - must not be null.
actual
,
Date
the given Date.
other
)

Returns true if the actual Date is equal to the given one according to underlying comparisonStrategy, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month and day of month, false otherwise
areInSameDayOfMonth
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month and day of month, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month, day of month and hour, false otherwise.
areInSameHour
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month, day of month and hour, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
areInSameHourWindow
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month, day of month, hour and minute, false otherwise.
areInSameMinute
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise.

private static boolean
private static boolean

Returns:

true if both date are in the same year and month, false otherwise
areInSameMonth
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year and month, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
areInSameSecond
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.

private static boolean

Returns:

true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.
areInSameSecondWindow
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.

private static boolean

Returns:

true if both date are in the same year, false otherwise
areInSameYear
(Date
the actual date. expected not be null
actual
,
Date
the other date. expected not be null
other
)

Returns true if both date are in the same year, false otherwise.

public void
assertHasDayOfMonth(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the day of month to compare actual day of month to
dayOfMonth
)

Verifies that the actual Date day of month is equal to the given day of month.

public void
assertHasDayOfWeek(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the day of week to compare actual day of week to, see Calendar#DAY_OF_WEEK for valid values
dayOfWeek
)

Verifies that the actual Date day of week is equal to the given day of week.

public void
assertHasHourOfDay(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the hour of day to compare actual hour of day to (24-hour clock)
hourOfDay
)

Verifies that the actual Date hour od day is equal to the given hour of day (24-hour clock).

public void
assertHasMillisecond(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the millisecond to compare actual millisecond to
millisecond
)

Verifies that the actual Date millisecond is equal to the given millisecond.

public void
assertHasMinute(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the minute to compare actual minute to
minute
)

Verifies that the actual Date minute is equal to the given minute.

public void
assertHasMonth(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the month to compare actual month to, see Calendar#MONTH for valid values
month
)

Verifies that the actual Date month is equal to the given month, month value starting at 1 (January=1, February=2, ...).

public void
assertHasSameTime(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the "expected" Date to compare actual time to
expected
)

Verifies that the actual Date has same time as the given Date.

public void
assertHasSecond(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the second to compare actual second to
second
)

Verifies that the actual Date second is equal to the given second.

public void
assertHasTime(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
long
the timestamp to compare actual time to
timestamp
)

Verifies that the actual Date time is equal to the given timestamp.

public void
assertHasYear(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the year to compare actual year to
year
)

Verifies that the actual Date year is equal to the given year.

public void
assertIsAfter(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date.
other
)

Verifies that the actual Date is strictly after the given one.

public void
assertIsAfterOrEqualTo(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date.
other
)

Verifies that the actual Date is after or equal to the given one.

public void
assertIsAfterYear(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the year to compare actual year to
year
)

Verifies that the actual Date is strictly after the given year.

public void
assertIsBefore(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the other date to compare actual with.
other
)

Verifies that the actual Date is strictly before the given one.

public void
assertIsBeforeOrEqualTo(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the other date to compare actual with.
other
)

Verifies that the actual Date is before or equal to the given one.

public void
assertIsBeforeYear(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
int
the year to compare actual year to
year
)

Verifies that the actual Date is strictly before the given year.

public void
assertIsBetween(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the period start, expected not to be null.
start
,
Date
the period end, expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Verifies that the actual Date is in start:end period.

public void
assertIsCloseTo(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
,
long
the delta used for date comparison, expressed in milliseconds
deltaInMilliseconds
)

Verifies that the actual Date is close to the other date by less than delta, if difference is equals to delta it is ok.

public void
assertIsEqualWithPrecision(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date.
other
,
TimeUnit
maximum precision for the comparison.
precision
)

Verifies that the actual Date is equal to the given one with precision.

public void
assertIsInSameDayAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same day of month (and thus in the same month and year).

public void
assertIsInSameHourAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are in the same hour (and thus in the same day of month, month and year).

public void
assertIsInSameHourWindowAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same hour, day of month, month and year.

public void
assertIsInSameMinuteAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are in the same minute, hour, day of month, month and year.

public void
assertIsInSameMinuteWindowAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same minute.

public void
assertIsInSameMonthAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same month (and thus in the same year).

public void
assertIsInSameSecondAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are in the same second, minute, hour, day of month, month and year.

public void
assertIsInSameSecondWindowAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are chronologically in the same second.

public void
assertIsInSameYearAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the given Date to compare actual Date to.
other
)

Verifies that actual and given Date are in the same year.

public void
assertIsInTheFuture(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
)

Verifies that the actual Date is strictly in the future.

public void
assertIsInThePast(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
)

Verifies that the actual Date is strictly in the past.

public void
assertIsNotBetween(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the period start, expected not to be null.
start
,
Date
the period end, expected not to be null.
end
,
boolean
whether to include start date in period.
inclusiveStart
,
boolean
whether to include end date in period.
inclusiveEnd
)

Verifies that the actual Date is not in start:end period..

public void
assertIsToday(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
)

Verifies that the actual Date is today, by comparing only year, month and day of actual to today (ie.

private void
private static void
dateParameterIsNotNull(Date
the date to check
date
)

used to check that the date to compare actual date to is not null, in that case throws a NullPointerException with an explicit message

private static void
endDateParameterIsNotNull(Date
the end date to check
end
)

used to check that the end of period date to compare actual date to is not null, in that case throws a NullPointerException with an explicit message

public Comparator<?>
public void
hasSameTimeAs(AssertionInfo
contains information about the assertion.
info
,
Date
the "actual" Date.
actual
,
Date
the date to compare actual time to
date
)

Verifies that the actual Date is equal to the given date by comparing their time.

public static Dates

Returns:

the singleton instance of this class.
instance
()

Returns the singleton instance of this class.

private boolean

Returns:

true if actual is after other according to underlying comparisonStrategy, false otherwise.
isAfter
(Date
the Date to compare to other
actual
,
Date
the Date to compare to actual
other
)

Returns true if actual is after other according to underlying comparisonStrategy, false otherwise.

private boolean

Returns:

true if the actual Date is after or equal to the given one according to underlying comparisonStrategy, false otherwise.
isAfterOrEqualTo
(Date
the actual date - must not be null.
actual
,
Date
the given Date.
other
)

Returns true if the actual Date is after or equal to the given one according to underlying comparisonStrategy, false otherwise.

private boolean

Returns:

true if actual is before other according to underlying comparisonStrategy, false otherwise.
isBefore
(Date
the Date to compare to other
actual
,
Date
the Date to compare to actual
other
)

Returns true if actual is before other according to underlying comparisonStrategy, false otherwise.

private boolean

Returns:

true if the actual Date is before or equal to the given one according to underlying comparisonStrategy, false otherwise.
isBeforeOrEqualTo
(Date
the actual date - must not be null.
actual
,
Date
the given Date.
other
)

Returns true if the actual Date is before or equal to the given one according to underlying comparisonStrategy, false otherwise.

private static void
startDateParameterIsNotNull(Date
the start date to check
start
)

used to check that the start of period date to compare actual date to is not null, in that case throws a NullPointerException with an explicit message

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait