public class DateTimeAssert extends org.assertj.core.api.AbstractAssert<DateTimeAssert,org.joda.time.DateTime>
DateTime
type.Modifier and Type | Field and Description |
---|---|
static String |
NULL_DATE_TIME_PARAMETER_MESSAGE |
Modifier | Constructor and Description |
---|---|
protected |
DateTimeAssert(Class<DateTimeAssert> selfType,
org.joda.time.DateTime actual)
Creates a new
. |
Modifier and Type | Method and Description |
---|---|
protected org.joda.time.DateTime |
getActual() |
DateTimeAssert |
hasDayOfMonth(int expectedDayOfMonth)
Verifies that the day of month of the actual
DateTime is equal to the given day of month |
DateTimeAssert |
hasHourOfDay(int expectedHourOfDay)
Verifies that the hour of the actual
DateTime is equal to the given hour |
DateTimeAssert |
hasMillisOfSecond(int expectedMillisOfSecond)
Verifies that the milliseconds of the actual
DateTime is equal to the given milliseconds |
DateTimeAssert |
hasMinuteOfHour(int expectedMinuteOfHour)
Verifies that the minute of the actual
DateTime is equal to the given minute |
DateTimeAssert |
hasMonthOfYear(int expectedMonthOfYear)
Verifies that the month of the actual
DateTime is equal to the given month |
DateTimeAssert |
hasSecondOfMinute(int expectedSecondOfMinute)
Verifies that the seconds of the actual
DateTime is equal to the given seconds |
DateTimeAssert |
hasYear(int expectedYear)
Verifies that the year of the actual
DateTime is equal to the given year |
DateTimeAssert |
isAfter(org.joda.time.DateTime other)
Verifies that the actual
DateTime is strictly after the given one. |
DateTimeAssert |
isAfter(String dateTimeAsString)
Same assertion as
isAfter(DateTime) but the DateTime is built from given String, which must follow
ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isAfterOrEqualTo(org.joda.time.DateTime other)
Verifies that the actual
DateTime is after or equals to the given one. |
DateTimeAssert |
isAfterOrEqualTo(String dateTimeAsString)
Same assertion as
isAfterOrEqualTo(DateTime) but the DateTime is built from given String, which
must follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isBefore(org.joda.time.DateTime other)
Verifies that the actual
DateTime is strictly before the given one. |
DateTimeAssert |
isBefore(String dateTimeAsString)
Same assertion as
isBefore(DateTime) but the DateTime is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isBeforeOrEqualTo(org.joda.time.DateTime other)
Verifies that the actual
DateTime is before or equals to the given one. |
DateTimeAssert |
isBeforeOrEqualTo(String dateTimeAsString)
Same assertion as
isBeforeOrEqualTo(DateTime) but the DateTime is built from given String, which
must follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isEqualTo(org.joda.time.DateTime expected)
Verifies that the actual
DateTime is equal to the given one in actual's DateTimeZone . |
DateTimeAssert |
isEqualTo(String dateTimeAsString)
Same assertion as
isEqualTo(DateTime) but the DateTime is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isEqualToIgnoringHours(org.joda.time.DateTime other)
Verifies that actual and given
DateTime have same year, month and day fields (hour, minute, second and
millisecond fields are ignored in comparison). |
DateTimeAssert |
isEqualToIgnoringMillis(org.joda.time.DateTime other)
Verifies that actual and given
DateTime have same year, month, day, hour, minute and second fields,
(millisecond fields are ignored in comparison). |
DateTimeAssert |
isEqualToIgnoringMinutes(org.joda.time.DateTime other)
Verifies that actual and given
DateTime have same year, month, day and hour fields (minute, second and
millisecond fields are ignored in comparison). |
DateTimeAssert |
isEqualToIgnoringSeconds(org.joda.time.DateTime other)
Verifies that actual and given
DateTime have same year, month, day, hour and minute fields (second and
millisecond fields are ignored in comparison). |
DateTimeAssert |
isIn(org.joda.time.DateTime... expected)
Verifies that the actual
DateTime is equal to one of the given DateTime in the actual DateTime's
DateTimeZone . |
DateTimeAssert |
isIn(String... dateTimesAsString)
Same assertion as
isIn(DateTime...) but the DateTime are built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isNotEqualTo(org.joda.time.DateTime expected)
Verifies that the actual value is not equal to the given one in actual's
DateTimeZone . |
DateTimeAssert |
isNotEqualTo(String dateTimeAsString)
Same assertion as
isNotEqualTo(DateTime) but the DateTime is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object) constructor. |
DateTimeAssert |
isNotIn(org.joda.time.DateTime... expected)
Verifies that the actual
DateTime is equal to one of the given DateTime in the actual DateTime's
DateTimeZone . |
DateTimeAssert |
isNotIn(String... dateTimesAsString)
Same assertion as
isNotIn(org.joda.time.DateTime...) but the DateTime is built from given String,
which must follow ISO DateTime format to allow calling DateTime(Object) constructor. |
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
public static final String NULL_DATE_TIME_PARAMETER_MESSAGE
protected DateTimeAssert(Class<DateTimeAssert> selfType, org.joda.time.DateTime actual)
DateTimeAssert
.selfType
- the "self type"actual
- the actual value to verifyprotected org.joda.time.DateTime getActual()
public DateTimeAssert hasYear(int expectedYear)
DateTime
is equal to the given year
Example :
assertThat(new DateTime("2000-01-01")).hasYear(1);
expectedYear
- the given year.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the year of the actual DateTime
is not equal to the given year.public DateTimeAssert hasMonthOfYear(int expectedMonthOfYear)
DateTime
is equal to the given month
Example :
assertThat(new DateTime("2000-01-01")).hasMonthOfYear(1);
expectedMonthOfYear
- the given month.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the month of the actual DateTime
is not equal to the given month.public DateTimeAssert hasDayOfMonth(int expectedDayOfMonth)
DateTime
is equal to the given day of month
Example :
assertThat(new DateTime("2000-01-01")).hasDayOfMonth(1);
expectedDayOfMonth
- the given day of month.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the day of month of the actual DateTime
is not equal to the given day of month.public DateTimeAssert hasHourOfDay(int expectedHourOfDay)
DateTime
is equal to the given hour
Example :
assertThat(new DateTime("2000-01-01T11:00:00")).hasHourOfDay(11);
expectedHourOfDay
- the given hour.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the hour of the actual DateTime
is not equal to the given hour.public DateTimeAssert hasMinuteOfHour(int expectedMinuteOfHour)
DateTime
is equal to the given minute
Example :
assertThat(new DateTime("2000-01-01T11:09:00")).hasMinuteOfHour(9);
expectedMinuteOfHour
- the given minute.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the minute of the actual DateTime
is not equal to the given minute.public DateTimeAssert hasSecondOfMinute(int expectedSecondOfMinute)
DateTime
is equal to the given seconds
Example :
assertThat(new DateTime("2000-01-01T11:09:39")).hasSecondOfMinute(39);
expectedSecondOfMinute
- the given seconds.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the seconds of the actual DateTime
is not equal to the given seconds.public DateTimeAssert hasMillisOfSecond(int expectedMillisOfSecond)
DateTime
is equal to the given milliseconds
Example :
assertThat(new DateTime("2000-01-01T11:09:39.145")).hasMillisOfSecond(145);
expectedMillisOfSecond
- the given milliseconds.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the milliseconds of the actual DateTime
is not equal to the given milliseconds.public DateTimeAssert isBefore(org.joda.time.DateTime other)
DateTime
is strictly before the given one.
Example :
assertThat(new DateTime("2000-01-01")).isBefore(new DateTime("2000-01-02"));
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is not strictly before the given one.public DateTimeAssert isBefore(String dateTimeAsString)
isBefore(DateTime)
but the DateTime
is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check..
Example :
// use directly String in comparison to avoid a conversion
assertThat(new DateTime("2000-01-01")).isBefore("2000-01-02");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not strictly before the DateTime
built from given
String.public DateTimeAssert isBeforeOrEqualTo(org.joda.time.DateTime other)
DateTime
is before or equals to the given one.
Assertion succeeds when both actual and given DateTime
are null.
Example :
assertThat(new DateTime("2000-01-01")).isBeforeOrEqualTo(new DateTime("2000-01-01"))
.isBeforeOrEqualTo(new DateTime("2000-01-02"));
// assertions succeed when both actual and expected are null
DateTime actual = null;
assertThat(actual).isBeforeOrEqualTo((DateTime)null);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
and given one is not.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is not before or equals to the given one.public DateTimeAssert isBeforeOrEqualTo(String dateTimeAsString)
isBeforeOrEqualTo(DateTime)
but the DateTime
is built from given String, which
must follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check..
Example :
// use String in comparison to avoid conversion
assertThat(new DateTime("2000-01-01")).isBeforeOrEqualTo("2000-01-01")
.isBeforeOrEqualTo("2000-01-02");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not before or equals to the DateTime
built from
given String.public DateTimeAssert isAfterOrEqualTo(org.joda.time.DateTime other)
DateTime
is after or equals to the given one.
Assertion succeeds when both actual and given DateTime
are null.
Example :
// assertions succeed
assertThat(new DateTime("2000-01-01")).isAfterOrEqualTo(new DateTime("2000-01-01"))
.isAfterOrEqualTo(new DateTime("1999-12-31"));
// assertions succeed when both actual and expected are null
DateTime actual = null;
assertThat(actual).isAfterOrEqualTo((DateTime)null);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
and given one is not.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is not after or equals to the given one.public DateTimeAssert isAfterOrEqualTo(String dateTimeAsString)
isAfterOrEqualTo(DateTime)
but the DateTime
is built from given String, which
must follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check.
Example :
// use String in comparison to avoid conversion
assertThat(new DateTime("2000-01-01")).isAfterOrEqualTo("2000-01-01")
.isAfterOrEqualTo("1999-12-31");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not after or equals to the DateTime
built from
given String.public DateTimeAssert isAfter(org.joda.time.DateTime other)
DateTime
is strictly after the given one.
Example :
assertThat(new DateTime("2000-01-01")).isAfter(new DateTime("1999-12-31"));
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is not strictly after the given one.public DateTimeAssert isAfter(String dateTimeAsString)
isAfter(DateTime)
but the DateTime
is built from given String, which must follow
ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check.
Example :
// use String in comparison to avoid conversion
assertThat(new DateTime("2000-01-01")).isAfter("1999-12-31");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not strictly after the DateTime
built from given
String.public DateTimeAssert isEqualToIgnoringMillis(org.joda.time.DateTime other)
DateTime
have same year, month, day, hour, minute and second fields,
(millisecond fields are ignored in comparison).
Note that given DateTime
is converted in actual's DateTimeZone
before comparison.
Assertion can fail with dateTimes in same chronological millisecond time window, e.g :
2000-01-01T00:00:01.000 and 2000-01-01T00:00:00.999.
Assertion fails as second fields differ even if time difference is only 1ms.
Code example :
// successfull assertions
DateTime dateTime1 = new DateTime(2000, 1, 1, 0, 0, 1, 0);
DateTime dateTime2 = new DateTime(2000, 1, 1, 0, 0, 1, 456);
assertThat(dateTime1).isEqualToIgnoringMillis(dateTime2);
// failing assertions (even if time difference is only 1ms)
DateTime dateTimeA = new DateTime(2000, 1, 1, 0, 0, 1, 0);
DateTime dateTimeB = new DateTime(2000, 1, 1, 0, 0, 0, 999);
assertThat(dateTimeA).isEqualToIgnoringMillis(dateTimeB);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is are not equal with milliseconds ignored.public DateTimeAssert isEqualToIgnoringSeconds(org.joda.time.DateTime other)
DateTime
have same year, month, day, hour and minute fields (second and
millisecond fields are ignored in comparison).
Note that given DateTime
is converted in actual's DateTimeZone
before comparison.
Assertion can fail with DateTimes in same chronological second time window, e.g :
2000-01-01T00:01:00.000 and 2000-01-01T00:00:59.000.
Assertion fails as minute fields differ even if time difference is only 1s.
Code example :
// successfull assertions
DateTime dateTime1 = new DateTime(2000, 1, 1, 23, 50, 0, 0);
DateTime dateTime2 = new DateTime(2000, 1, 1, 23, 50, 10, 456);
assertThat(dateTime1).isEqualToIgnoringSeconds(dateTime2);
// failing assertions (even if time difference is only 1ms)
DateTime dateTimeA = new DateTime(2000, 1, 1, 23, 50, 00, 000);
DateTime dateTimeB = new DateTime(2000, 1, 1, 23, 49, 59, 999);
assertThat(dateTimeA).isEqualToIgnoringSeconds(dateTimeB);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is are not equal with second and millisecond fields ignored.public DateTimeAssert isEqualToIgnoringMinutes(org.joda.time.DateTime other)
DateTime
have same year, month, day and hour fields (minute, second and
millisecond fields are ignored in comparison).
Note that given DateTime
is converted in actual's DateTimeZone
before comparison.
Assertion can fail with dateTimes in same chronological second time window, e.g :
2000-01-01T01:00:00.000 and 2000-01-01T00:59:59.000.
Time difference is only 1s but hour fields differ.
Code example :
// successfull assertions
DateTime dateTime1 = new DateTime(2000, 1, 1, 23, 50, 0, 0);
DateTime dateTime2 = new DateTime(2000, 1, 1, 23, 00, 2, 7);
assertThat(dateTime1).isEqualToIgnoringMinutes(dateTime2);
// failing assertions (even if time difference is only 1ms)
DateTime dateTimeA = new DateTime(2000, 1, 1, 01, 00, 00, 000);
DateTime dateTimeB = new DateTime(2000, 1, 1, 00, 59, 59, 999);
assertThat(dateTimeA).isEqualToIgnoringMinutes(dateTimeB);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is are not equal ignoring minute, second and millisecond
fields.public DateTimeAssert isEqualToIgnoringHours(org.joda.time.DateTime other)
DateTime
have same year, month and day fields (hour, minute, second and
millisecond fields are ignored in comparison).
Note that given DateTime
is converted in actual's DateTimeZone
before comparison.
Assertion can fail with dateTimes in same chronological minute time window, e.g :
2000-01-01T23:59:00.000 and 2000-01-02T00:00:00.000.
Time difference is only 1min but day fields differ.
Code example :
// successfull assertions
DateTime dateTime1 = new DateTime(2000, 1, 1, 23, 59, 59, 999);
DateTime dateTime2 = new DateTime(2000, 1, 1, 00, 00, 00, 000);
assertThat(dateTime1).isEqualToIgnoringHours(dateTime2);
// failing assertions (even if time difference is only 1ms)
DateTime dateTimeA = new DateTime(2000, 1, 2, 00, 00, 00, 000);
DateTime dateTimeB = new DateTime(2000, 1, 1, 23, 59, 59, 999);
assertThat(dateTimeA).isEqualToIgnoringHours(dateTimeB);
other
- the given DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if other DateTime
is null
.AssertionError
- if the actual DateTime
is are not equal with second and millisecond fields ignored.public DateTimeAssert isEqualTo(org.joda.time.DateTime expected)
DateTime
is equal to the given one in actual's DateTimeZone
.
Assertion succeeds when both actual and given DateTime
are null.
Example :
// assertions succeed
assertThat(new DateTime("2000-01-01")).isEqualTo(new DateTime("2000-01-01"));
DateTime actual = null;
DateTime other = null;
assertThat(actual).isEqualTo(other);
expected
- the given value to compare the actual value to.this
assertion object.AssertionError
- if the actual DateTime
is not equal to the DateTime
in the actual DateTime's
DateTimeZone.public DateTimeAssert isEqualTo(String dateTimeAsString)
isEqualTo(DateTime)
but the DateTime
is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check.
Example :
// use directly String in comparison to avoid a conversion
assertThat(new DateTime("2000-01-01")).isEqualTo("2000-01-01");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not equal to the DateTime
built from given String.public DateTimeAssert isNotEqualTo(org.joda.time.DateTime expected)
DateTimeZone
.
Example :
assertThat(new DateTime("2000-01-01")).isNotEqualTo(new DateTime("2000-01-15"));
expected
- the given value to compare the actual value to.this
assertion object.AssertionError
- if the actual DateTime
is equal to the DateTime
in the actual DateTime's
DateTimeZone.public DateTimeAssert isNotEqualTo(String dateTimeAsString)
isNotEqualTo(DateTime)
but the DateTime
is built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
created from the given String is built in the DateTimeZone
of the
DateTime
to check.
Example :
// use directly String in comparison to avoid a conversion
assertThat(new DateTime("2000-01-01")).isNotEqualTo("2000-01-15");
dateTimeAsString
- String representing a DateTime
.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is equal to the DateTime
built from given String.public DateTimeAssert isIn(org.joda.time.DateTime... expected)
DateTime
is equal to one of the given DateTime
in the actual DateTime's
DateTimeZone
.
Example :
assertThat(new DateTime("2000-01-01")).isIn(new DateTime("1999-12-31"), new DateTime("2000-01-01"));
expected
- the given DateTime
s to compare the actual value to.this
assertion object.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the actual DateTime
is not in the given DateTime
s.public DateTimeAssert isIn(String... dateTimesAsString)
isIn(DateTime...)
but the DateTime
are built from given String, which must
follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
s created from the given Strings are built in the DateTimeZone
of the
DateTime
to check..
Example :
// use String based representation of LocalDateTime
assertThat(new DateTime("2000-01-01")).isIn("1999-12-31", "2000-01-01");
dateTimesAsString
- String array representing DateTime
s.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not in the DateTime
s built from given Strings.public DateTimeAssert isNotIn(org.joda.time.DateTime... expected)
DateTime
is equal to one of the given DateTime
in the actual DateTime's
DateTimeZone
.
Example :
assertThat(new DateTime("2000-01-01")).isNotIn(new DateTime("1999-12-31"), new DateTime("2000-01-02"));
expected
- the given DateTime
s to compare the actual value to.this
assertion object.AssertionError
- if the actual DateTime
is null
.AssertionError
- if the actual DateTime
is not in the given DateTime
s.public DateTimeAssert isNotIn(String... dateTimesAsString)
isNotIn(org.joda.time.DateTime...)
but the DateTime
is built from given String,
which must follow ISO DateTime format to allow calling DateTime(Object)
constructor.
Note that the DateTime
s created from the given Strings are built in the DateTimeZone
of the
DateTime
to check..
Example :
// use String based representation of DateTime
assertThat(new DateTime("2000-01-01")).isNotIn("1999-12-31", "2000-01-02");
dateTimesAsString
- String array representing DateTime
s.AssertionError
- if the actual DateTime
is null
.IllegalArgumentException
- if given String is null or can't be converted to a DateTime
.AssertionError
- if the actual DateTime
is not equal to the DateTime
built from given String.Copyright © 2018 AssertJ. All rights reserved.