Class DateAssert
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<DateAssert,java.util.Date>
-
- org.fest.assertions.api.DateAssert
-
- All Implemented Interfaces:
Assert<DateAssert,java.util.Date>
,Descriptable<DateAssert>
,ExtensionPoints<DateAssert,java.util.Date>
public class DateAssert extends AbstractAssert<DateAssert,java.util.Date>
Assertions forDate
s.To create a new instance of this class invoke
Note that assertions with date parameter comes with two flavor, one is obviously a
.Assertions.assertThat(Date)
Date
and the other is a String representing a Date.
For the latter, the default format follows ISO 8901 : "yyyy-MM-dd", user can override it with a custom format by callingwithDateFormat(DateFormat)
.
The user custom format will then be used for all next Date assertions (i.e not limited to the current assertion) in the test suite.
To turn back to default format, simply callwithIsoDateFormat()
.- Author:
- Tomasz Nurkiewicz (thanks for giving assertions idea), Joel Costigliola, Mikhail Mazursky
-
-
Field Summary
-
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DateAssert(java.util.Date actual)
Creates a newDateAssert
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DateAssert
hasTime(long timestamp)
Verifies that the actualDate
has the same time as the given timestamp.DateAssert
isAfter(java.lang.String dateAsString)
Same assertion asisAfter(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isAfter(java.util.Date other)
Verifies that the actualDate
is strictly after the given one.DateAssert
isAfterOrEqualsTo(java.lang.String dateAsString)
Same assertion asisAfterOrEqualsTo(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isAfterOrEqualsTo(java.util.Date other)
Verifies that the actualDate
is after or equals to the given one.DateAssert
isAfterYear(int year)
Verifies that the actualDate
is strictly after the given year.DateAssert
isBefore(java.lang.String dateAsString)
Same assertion asisBefore(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isBefore(java.util.Date other)
Verifies that the actualDate
is strictly before the given one.DateAssert
isBeforeOrEqualsTo(java.lang.String dateAsString)
Same assertion asisBeforeOrEqualsTo(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isBeforeOrEqualsTo(java.util.Date other)
Verifies that the actualDate
is before or equals to the given one.DateAssert
isBeforeYear(int year)
Verifies that the actualDate
is strictly before the given year.DateAssert
isBetween(java.lang.String start, java.lang.String end)
Same assertion asisBetween(Date, Date)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isBetween(java.lang.String start, java.lang.String end, boolean inclusiveStart, boolean inclusiveEnd)
Same assertion asisBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isBetween(java.util.Date start, java.util.Date end)
Verifies that the actualDate
is in [start, end[ period (start included, end excluded).DateAssert
isBetween(java.util.Date start, java.util.Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is in the given period defined by start and end dates.
To include start in the period set inclusiveStart parameter totrue
.
To include end in the period set inclusiveEnd parameter totrue
.DateAssert
isCloseTo(java.lang.String dateAsString, long deltaInMilliseconds)
Same assertion asisCloseTo(Date, long)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isCloseTo(java.util.Date other, long deltaInMilliseconds)
Verifies that the actualDate
is close to the other date by less than delta (expressed in milliseconds), if difference is equals to delta it's ok.DateAssert
isEqualTo(java.lang.String dateAsString)
Same assertion asisEqualTo(Date date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isIn(java.lang.String... datesAsString)
Same assertion asAssert.isIn(Object...)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameDayAs(java.lang.String dateAsString)
Same assertion asisInSameDayAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameDayAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same day of month (and thus in the same month and year).DateAssert
isInSameHourAs(java.lang.String dateAsString)
Same assertion asisInSameHourAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameHourAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same hour (and thus in the same day, month and year).DateAssert
isInSameMinuteAs(java.lang.String dateAsString)
Same assertion asisInSameMinuteAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameMinuteAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same minute (and thus in the same hour, day, month and year).DateAssert
isInSameMonthAs(java.lang.String dateAsString)
Same assertion asisInSameMonthAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameMonthAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same month (and thus in the same year).DateAssert
isInSameSecondAs(java.lang.String dateAsString)
Same assertion asisInSameSecondAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameSecondAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same second (and thus in the same minute, hour, day, month and year).DateAssert
isInSameYearAs(java.lang.String dateAsString)
Same assertion asisInSameYearAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isInSameYearAs(java.util.Date other)
Verifies that actual and givenDate
are in the same year.DateAssert
isInTheFuture()
Verifies that the actualDate
is strictly in the future.DateAssert
isInThePast()
Verifies that the actualDate
is strictly in the past.DateAssert
isInWithStringDateCollection(java.util.Collection<java.lang.String> datesAsString)
Same assertion asAssert.isIn(Iterable)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).
Method signature could not beisIn(Collection<String>)
because it would be same signature asisIn(Collection<Date>)
since java collection type are erased at runtime.DateAssert
isNotBetween(java.lang.String start, java.lang.String end)
Same assertion asisNotBetween(Date, Date)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isNotBetween(java.lang.String start, java.lang.String end, boolean inclusiveStart, boolean inclusiveEnd)
Same assertion asisNotBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isNotBetween(java.util.Date start, java.util.Date end)
Verifies that the actualDate
is not in [start, end[ periodDateAssert
isNotBetween(java.util.Date start, java.util.Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is not in the given period defined by start and end dates.
To include start in the period set inclusiveStart parameter totrue
.
To include end in the period set inclusiveEnd parameter totrue
.DateAssert
isNotEqualTo(java.lang.String dateAsString)
Same assertion asisNotEqualTo(Date date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isNotIn(java.lang.String... datesAsString)
Same assertion asAssert.isNotIn(Object...)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).DateAssert
isNotInWithStringDateCollection(java.util.Collection<java.lang.String> datesAsString)
Same assertion asAssert.isNotIn(Iterable)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).
Method signature could not beisNotIn(Collection<String>)
because it would be same signature asisNotIn(Collection<Date>)
since java collection type are erased at runtime.DateAssert
isToday()
Verifies that the actualDate
is today, that is matching current year, month and day (no check on hour, minute, second, milliseconds).DateAssert
isWithinDayOfMonth(int dayOfMonth)
Verifies that the actualDate
day of month is equal to the given day of month.DateAssert
isWithinDayOfWeek(int dayOfWeek)
Verifies that the actualDate
day of week is equal to the given day of week (seeCalendar.DAY_OF_WEEK
for valid values).DateAssert
isWithinHourOfDay(int hourOfDay)
Verifies that the actualDate
hour od day is equal to the given hour of day (24-hour clock).DateAssert
isWithinMillisecond(int millisecond)
Verifies that the actualDate
millisecond is equal to the given millisecond.DateAssert
isWithinMinute(int minute)
Verifies that the actualDate
minute is equal to the given minute.DateAssert
isWithinMonth(int month)
Verifies that the actualDate
month is equal to the given month, month value starting at 1 (January=1, February=2, ...).DateAssert
isWithinSecond(int second)
Verifies that the actualDate
second is equal to the given second.DateAssert
isWithinYear(int year)
Verifies that the actualDate
year is equal to the given year.static void
useDateFormat(java.text.DateFormat userCustomDateFormat)
For String based Date assertions likeisBefore(String)
, given String is expected to follow the default Date format, that is ISO 8601 format : "yyyy-MM-dd".static void
useIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.DateAssert
usingComparator(java.util.Comparator<? super java.util.Date> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.DateAssert
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.DateAssert
withDateFormat(java.text.DateFormat userCustomDateFormat)
For String based Date assertions likeisBefore(String)
, given String is expected to follow the default Date format, that is ISO 8601 format : "yyyy-MM-dd".DateAssert
withIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.-
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage
-
-
-
-
Constructor Detail
-
DateAssert
protected DateAssert(java.util.Date actual)
Creates a newDateAssert
.- Parameters:
actual
- the target to verify.
-
-
Method Detail
-
isEqualTo
public DateAssert isEqualTo(java.lang.String dateAsString)
Same assertion asisEqualTo(Date date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual and given Date represented as String are not equal.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isNotEqualTo
public DateAssert isNotEqualTo(java.lang.String dateAsString)
Same assertion asisNotEqualTo(Date date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual and given Date represented as String are equal.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isIn
public DateAssert isIn(java.lang.String... datesAsString)
Same assertion asAssert.isIn(Object...)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
datesAsString
- the given Dates represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual is not in given Dates represented as String.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isInWithStringDateCollection
public DateAssert isInWithStringDateCollection(java.util.Collection<java.lang.String> datesAsString)
Same assertion asAssert.isIn(Iterable)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).
Method signature could not beisIn(Collection<String>)
because it would be same signature asisIn(Collection<Date>)
since java collection type are erased at runtime.- Parameters:
datesAsString
- the given Dates represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual is not in given Dates represented as String.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isNotIn
public DateAssert isNotIn(java.lang.String... datesAsString)
Same assertion asAssert.isNotIn(Object...)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
datesAsString
- the given Dates represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual is in given Dates represented as String.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isNotInWithStringDateCollection
public DateAssert isNotInWithStringDateCollection(java.util.Collection<java.lang.String> datesAsString)
Same assertion asAssert.isNotIn(Iterable)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).
Method signature could not beisNotIn(Collection<String>)
because it would be same signature asisNotIn(Collection<Date>)
since java collection type are erased at runtime.- Parameters:
datesAsString
- the given Dates represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if actual is in given Dates represented as String.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isBefore
public DateAssert isBefore(java.util.Date other)
Verifies that the actualDate
is strictly before the given one.- Parameters:
other
- the given Date.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if otherDate
isnull
.java.lang.AssertionError
- if the actualDate
is not strictly before the given one.
-
isBefore
public DateAssert isBefore(java.lang.String dateAsString)
Same assertion asisBefore(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if given date as String isnull
.java.lang.AssertionError
- if the actualDate
is not strictly before the given Date represented as String.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isBeforeOrEqualsTo
public DateAssert isBeforeOrEqualsTo(java.util.Date other)
Verifies that the actualDate
is before or equals to the given one.- Parameters:
other
- the given Date.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if otherDate
isnull
.java.lang.AssertionError
- if the actualDate
is not before or equals to the given one.
-
isBeforeOrEqualsTo
public DateAssert isBeforeOrEqualsTo(java.lang.String dateAsString)
Same assertion asisBeforeOrEqualsTo(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if given date as String isnull
.java.lang.AssertionError
- if the actualDate
is not before or equals to the given Date represented as String.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isAfter
public DateAssert isAfter(java.util.Date other)
Verifies that the actualDate
is strictly after the given one.- Parameters:
other
- the given Date.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if otherDate
isnull
.java.lang.AssertionError
- if the actualDate
is not strictly after the given one.
-
isAfter
public DateAssert isAfter(java.lang.String dateAsString)
Same assertion asisAfter(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if given date as String isnull
.java.lang.AssertionError
- if the actualDate
is not strictly after the given Date represented as String.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isAfterOrEqualsTo
public DateAssert isAfterOrEqualsTo(java.util.Date other)
Verifies that the actualDate
is after or equals to the given one.- Parameters:
other
- the given Date.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if otherDate
isnull
.java.lang.AssertionError
- if the actualDate
is not after or equals to the given one.
-
isAfterOrEqualsTo
public DateAssert isAfterOrEqualsTo(java.lang.String dateAsString)
Same assertion asisAfterOrEqualsTo(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if given date as String isnull
.java.lang.AssertionError
- if the actualDate
is not after or equals to the given Date represented as String.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isBetween
public DateAssert isBetween(java.util.Date start, java.util.Date end)
Verifies that the actualDate
is in [start, end[ period (start included, end excluded).- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if startDate
isnull
.java.lang.NullPointerException
- if endDate
isnull
.java.lang.AssertionError
- if the actualDate
is not in [start, end[ period.
-
isBetween
public DateAssert isBetween(java.lang.String start, java.lang.String end)
Same assertion asisBetween(Date, Date)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if start Date as String isnull
.java.lang.NullPointerException
- if end Date as String isnull
.java.lang.AssertionError
- if the actualDate
is not in [start, end[ period.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isBetween
public DateAssert isBetween(java.util.Date start, java.util.Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is in the given period defined by start and end dates.
To include start in the period set inclusiveStart parameter totrue
.
To include end in the period set inclusiveEnd parameter totrue
.- Parameters:
start
- the period start, expected not to be null.end
- the period end, expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- ifactual
isnull
.java.lang.NullPointerException
- if startDate
isnull
.java.lang.NullPointerException
- if endDate
isnull
.java.lang.AssertionError
- if the actualDate
is not in (start, end) period.
-
isBetween
public DateAssert isBetween(java.lang.String start, java.lang.String end, boolean inclusiveStart, boolean inclusiveEnd)
Same assertion asisBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
start
- the period start, expected not to be null.end
- the period end, expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- ifactual
isnull
.java.lang.NullPointerException
- if start Date as String isnull
.java.lang.NullPointerException
- if end Date as String isnull
.java.lang.AssertionError
- if the actualDate
is not in (start, end) period.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isNotBetween
public DateAssert isNotBetween(java.util.Date start, java.util.Date end, boolean inclusiveStart, boolean inclusiveEnd)
Verifies that the actualDate
is not in the given period defined by start and end dates.
To include start in the period set inclusiveStart parameter totrue
.
To include end in the period set inclusiveEnd parameter totrue
.- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- ifactual
isnull
.java.lang.NullPointerException
- if startDate
isnull
.java.lang.NullPointerException
- if endDate
isnull
.java.lang.AssertionError
- if the actualDate
is not in (start, end) period.
-
isNotBetween
public DateAssert isNotBetween(java.lang.String start, java.lang.String end, boolean inclusiveStart, boolean inclusiveEnd)
Same assertion asisNotBetween(Date, Date, boolean, boolean)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.inclusiveStart
- wether to include start date in period.inclusiveEnd
- wether to include end date in period.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- ifactual
isnull
.java.lang.NullPointerException
- if start Date as String isnull
.java.lang.NullPointerException
- if end Date as String isnull
.java.lang.AssertionError
- if the actualDate
is not in (start, end) period.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isNotBetween
public DateAssert isNotBetween(java.util.Date start, java.util.Date end)
Verifies that the actualDate
is not in [start, end[ period- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if startDate
isnull
.java.lang.NullPointerException
- if endDate
isnull
.java.lang.AssertionError
- if the actualDate
is in [start, end[ period.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isNotBetween
public DateAssert isNotBetween(java.lang.String start, java.lang.String end)
Same assertion asisNotBetween(Date, Date)
but given Dates are represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
start
- the period start (inclusive), expected not to be null.end
- the period end (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.NullPointerException
- if start Date as String isnull
.java.lang.NullPointerException
- if end Date as String isnull
.java.lang.AssertionError
- if the actualDate
is in [start, end[ period.java.lang.AssertionError
- if one of the given date as String could not be converted to a Date.
-
isInThePast
public DateAssert isInThePast()
Verifies that the actualDate
is strictly in the past.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
is not in the past.
-
isToday
public DateAssert isToday()
Verifies that the actualDate
is today, that is matching current year, month and day (no check on hour, minute, second, milliseconds).- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
is not today.
-
isInTheFuture
public DateAssert isInTheFuture()
Verifies that the actualDate
is strictly in the future.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
is not in the future.
-
isBeforeYear
public DateAssert isBeforeYear(int year)
Verifies that the actualDate
is strictly before the given year.- Parameters:
year
- the year to compare actual year to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
year is after or equals to the given year.
-
isAfterYear
public DateAssert isAfterYear(int year)
Verifies that the actualDate
is strictly after the given year.- Parameters:
year
- the year to compare actual year to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
year is before or equals to the given year.
-
isWithinYear
public DateAssert isWithinYear(int year)
Verifies that the actualDate
year is equal to the given year.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
year
- the year to compare actual year to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
year is not equal to the given year.
-
isWithinMonth
public DateAssert isWithinMonth(int month)
Verifies that the actualDate
month is equal to the given month, month value starting at 1 (January=1, February=2, ...).Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
month
- the month to compare actual month to, month value starting at 1 (January=1, February=2, ...).- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
month is not equal to the given month.
-
isWithinDayOfMonth
public DateAssert isWithinDayOfMonth(int dayOfMonth)
Verifies that the actualDate
day of month is equal to the given day of month.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
dayOfMonth
- the day of month to compare actual day of month to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
month is not equal to the given day of month.
-
isWithinDayOfWeek
public DateAssert isWithinDayOfWeek(int dayOfWeek)
Verifies that the actualDate
day of week is equal to the given day of week (seeCalendar.DAY_OF_WEEK
for valid values).Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
dayOfWeek
- the day of week to compare actual day of week to, seeCalendar.DAY_OF_WEEK
for valid values- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
week is not equal to the given day of week.
-
isWithinHourOfDay
public DateAssert isWithinHourOfDay(int hourOfDay)
Verifies that the actualDate
hour od day is equal to the given hour of day (24-hour clock).Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
hourOfDay
- the hour of day to compare actual hour of day to (24-hour clock)- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
hour is not equal to the given hour.
-
isWithinMinute
public DateAssert isWithinMinute(int minute)
Verifies that the actualDate
minute is equal to the given minute.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
minute
- the minute to compare actual minute to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
minute is not equal to the given minute.
-
isWithinSecond
public DateAssert isWithinSecond(int second)
Verifies that the actualDate
second is equal to the given second.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
second
- the second to compare actual second to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
second is not equal to the given second.
-
isWithinMillisecond
public DateAssert isWithinMillisecond(int millisecond)
Verifies that the actualDate
millisecond is equal to the given millisecond.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
millisecond
- the millisecond to compare actual millisecond to- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
millisecond is not equal to the given millisecond.
-
isInSameYearAs
public DateAssert isInSameYearAs(java.util.Date other)
Verifies that actual and givenDate
are in the same year.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same year.
-
isInSameYearAs
public DateAssert isInSameYearAs(java.lang.String dateAsString)
Same assertion asisInSameYearAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and given Date represented as String are not in the same year.java.lang.AssertionError
- if the given date as String could not be converted to a Date.
-
isInSameMonthAs
public DateAssert isInSameMonthAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same month (and thus in the same year).If you want to compare month only (without year), use :
assertThat(myDate).isWithinMonth(monthOf(otherDate))
SeeDates.monthOf(Date)
to get the month of a given Date.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same month.
-
isInSameMonthAs
public DateAssert isInSameMonthAs(java.lang.String dateAsString)
Same assertion asisInSameMonthAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same month.
-
isInSameDayAs
public DateAssert isInSameDayAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same day of month (and thus in the same month and year).If you want to compare day of month only (without month and year), you could write :
assertThat(myDate).isWithinDayOfMonth(dayOfMonthOf(otherDate))
seeDates.dayOfMonthOf(Date)
to get the day of month of a given Date.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same day of month.
-
isInSameDayAs
public DateAssert isInSameDayAs(java.lang.String dateAsString)
Same assertion asisInSameDayAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same day of month.
-
isInSameHourAs
public DateAssert isInSameHourAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same hour (and thus in the same day, month and year).If you want to compare hour only (without day, month and year), you could write :
assertThat(myDate).isWithinHour(hourOfDayOf(otherDate))
seeDates.hourOfDay(Date)
to get the hour of a given Date.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same hour.
-
isInSameHourAs
public DateAssert isInSameHourAs(java.lang.String dateAsString)
Same assertion asisInSameHourAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same hour.
-
isInSameMinuteAs
public DateAssert isInSameMinuteAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same minute (and thus in the same hour, day, month and year).If you want to compare minute only (without hour, day, month and year), you could write :
assertThat(myDate).isWithinMinute(minuteOf(otherDate))
seeDates.minuteOf(Date)
to get the minute of a given Date.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same minute.
-
isInSameMinuteAs
public DateAssert isInSameMinuteAs(java.lang.String dateAsString)
Same assertion asisInSameMinuteAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same minute.
-
isInSameSecondAs
public DateAssert isInSameSecondAs(java.util.Date other)
Verifies that actual and givenDate
are chronologically in the same second (and thus in the same minute, hour, day, month and year).If you want to compare second only (without minute, hour, day, month and year), you could write :
assertThat(myDate).isWithinSecond(secondOf(otherDate))
seeDates.secondOf(Date)
to get the second of a given Date.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the givenDate
to compare actualDate
to.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same second.
-
isInSameSecondAs
public DateAssert isInSameSecondAs(java.lang.String dateAsString)
Same assertion asisInSameSecondAs(Date)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if actual and givenDate
are not in the same second.
-
isCloseTo
public DateAssert isCloseTo(java.util.Date other, long deltaInMilliseconds)
Verifies that the actualDate
is close to the other date by less than delta (expressed in milliseconds), if difference is equals to delta it's ok.One can use handy
TimeUnit
to convert a duration in milliseconds, for example you can express a delta of 5 seconds withTimeUnit.SECONDS.toMillis(5)
.Note that using a custom comparator has no effect on this assertion (see
usingComparator(Comparator)
.- Parameters:
other
- the date to compare actual todeltaInMilliseconds
- the delta used for date comparison, expressed in milliseconds- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- ifDate
parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
week is not close to the given date by less than delta.
-
isCloseTo
public DateAssert isCloseTo(java.lang.String dateAsString, long deltaInMilliseconds)
Same assertion asisCloseTo(Date, long)
but given Date is represented as String either with ISO date format (yyyy-MM-dd) or user custom date format (set with methodwithDateFormat(DateFormat)
).- Parameters:
dateAsString
- the given Date represented as String in default or custom date format.deltaInMilliseconds
- the delta used for date comparison, expressed in milliseconds- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if dateAsString parameter isnull
.java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
week is not close to the given date by less than delta.
-
hasTime
public DateAssert hasTime(long timestamp)
Verifies that the actualDate
has the same time as the given timestamp.Both time or timestamp express a number of milliseconds since January 1, 1970, 00:00:00 GMT.
- Parameters:
timestamp
- the timestamp to compare actual time to.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualDate
isnull
.java.lang.AssertionError
- if the actualDate
time is not equal to the given timestamp.- See Also:
Date.getTime()
-
withDateFormat
public DateAssert withDateFormat(java.text.DateFormat userCustomDateFormat)
For String based Date assertions likeisBefore(String)
, given String is expected to follow the default Date format, that is ISO 8601 format : "yyyy-MM-dd".With this method, user can specify its own date format, replacing the current date format for all future Date assertions in the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
To revert to default format simply call
withIsoDateFormat()
.- Parameters:
userCustomDateFormat
- the new Date format used for String based Date assertions.- Returns:
- this assertion object.
-
useDateFormat
public static void useDateFormat(java.text.DateFormat userCustomDateFormat)
For String based Date assertions likeisBefore(String)
, given String is expected to follow the default Date format, that is ISO 8601 format : "yyyy-MM-dd".With this method, user can specify its own date format, replacing the current date format for all future Date assertions in the test suite (i.e. not only the current assertions) since custom DateFormat is stored in a static field.
To revert to default format simply call
useIsoDateFormat()
(static method) orwithIsoDateFormat()
.- Parameters:
userCustomDateFormat
- the new Date format used for String based Date assertions.
-
withIsoDateFormat
public DateAssert withIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.- Returns:
- this assertion object.
-
useIsoDateFormat
public static void useIsoDateFormat()
Use ISO 8601 date format ("yyyy-MM-dd") for String based Date assertions.
-
usingComparator
public DateAssert usingComparator(java.util.Comparator<? super java.util.Date> customComparator)
Description copied from class:AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<DateAssert,java.util.Date>
- Overrides:
usingComparator
in classAbstractAssert<DateAssert,java.util.Date>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultComparator
public DateAssert usingDefaultComparator()
Description copied from class:AbstractAssert
Revert to standard comparison for incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.- Specified by:
usingDefaultComparator
in interfaceAssert<DateAssert,java.util.Date>
- Overrides:
usingDefaultComparator
in classAbstractAssert<DateAssert,java.util.Date>
- Returns:
this
assertion object.
-
-