Package org.assertj.core.api
Class AbstractLocalDateAssert<SELF extends AbstractLocalDateAssert<SELF>>
java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,LocalDate>
org.assertj.core.api.AbstractTemporalAssert<SELF,LocalDate>
org.assertj.core.api.AbstractLocalDateAssert<SELF>
- Type Parameters:
SELF- the "self" type of this assertion class.
- All Implemented Interfaces:
Assert<SELF,,LocalDate> Descriptable<SELF>,ExtensionPoints<SELF,LocalDate>
- Direct Known Subclasses:
LocalDateAssert
public abstract class AbstractLocalDateAssert<SELF extends AbstractLocalDateAssert<SELF>>
extends AbstractTemporalAssert<SELF,LocalDate>
Assertions for
LocalDate type from new Date & Time API introduced in Java 8.-
Field Summary
FieldsFields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractLocalDateAssert(LocalDate actual, Class<?> selfType) Creates a new.AbstractLocalDateAssert -
Method Summary
Modifier and TypeMethodDescriptionhasDayOfMonth(int day) Verifies that actualLocalDateis on the given day.Verifies that actualLocalDateis in the given month.hasMonthValue(int month) Verifies that actualLocalDateis in the given month.hasYear(int year) Verifies that actualLocalDateis in the given year.Same assertion asisAfter(LocalDate)but theLocalDateis built from given a String that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Verifies that the actualLocalDateis strictly after the given one.isAfterOrEqualTo(String localDateAsString) Same assertion asisAfterOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.isAfterOrEqualTo(LocalDate other) Verifies that the actualLocalDateis after or equals to the given one.Same assertion asisBefore(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Verifies that the actualLocalDateis strictly before the given one.isBeforeOrEqualTo(String localDateAsString) Same assertion asisBeforeOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.isBeforeOrEqualTo(LocalDate other) Verifies that the actualLocalDateis before or equals to the given one.Same assertion asisBetween(LocalDate, LocalDate)but here you passLocalDateString representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Verifies that the actualLocalDateis in the [start, end] period (start and end included).Same assertion asAbstractAssert.isEqualTo(Object)(where Object is expected to beLocalDate) but here you passLocalDateString representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beLocalDate) but here you passLocalDateString representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Verifies that the actualLocalDateis strictly in the future.Verifies that the actualLocalDateis strictly in the past.isNotEqualTo(String localDateAsString) Same assertion asAbstractAssert.isNotEqualTo(Object)(where Object is expected to beLocalDate) but here you passLocalDateString representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beLocalDate) but here you passLocalDateString representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.isStrictlyBetween(String startExclusive, String endExclusive) Same assertion asisStrictlyBetween(LocalDate, LocalDate)but here you passLocalDateString representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.isStrictlyBetween(LocalDate startExclusive, LocalDate endExclusive) Verifies that the actualLocalDateis in the ]start, end[ period (start and end excluded).isToday()Verifies that the actualLocalDateis today, that is matching current year, month and day.protected LocalDateObtains an instance ofTEMPORALfrom a string representation in ISO date format.Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
isCloseTo, isCloseTo, usingComparator, usingComparator, usingDefaultComparatorMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Field Details
-
NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
- See Also:
-
-
Constructor Details
-
AbstractLocalDateAssert
Creates a new.AbstractLocalDateAssert- Parameters:
actual- the actual value to verifyselfType- the "self type"
-
-
Method Details
-
isBefore
Verifies that the actualLocalDateis strictly before the given one.Example :
assertThat(parse("2000-01-01")).isBefore(parse("2000-01-02"));- Parameters:
other- the givenLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if otherLocalDateisnull.AssertionError- if the actualLocalDateis not strictly before the given one.
-
isBefore
Same assertion asisBefore(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01")).isBefore("2000-01-02");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not strictly before theLocalDatebuilt from given String.
-
isBeforeOrEqualTo
Verifies that the actualLocalDateis before or equals to the given one.Example :
assertThat(parse("2000-01-01")).isBeforeOrEqualTo(parse("2000-01-01")) .isBeforeOrEqualTo(parse("2000-01-02"));- Parameters:
other- the givenLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if otherLocalDateisnull.AssertionError- if the actualLocalDateis not before or equals to the given one.
-
isBeforeOrEqualTo
Same assertion asisBeforeOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01")).isBeforeOrEqualTo("2000-01-01") .isBeforeOrEqualTo("2000-01-02");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not before or equals to theLocalDatebuilt from given String.
-
isAfterOrEqualTo
Verifies that the actualLocalDateis after or equals to the given one.Example :
assertThat(parse("2000-01-01")).isAfterOrEqualTo(parse("2000-01-01")) .isAfterOrEqualTo(parse("1999-12-31"));- Parameters:
other- the givenLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if otherLocalDateisnull.AssertionError- if the actualLocalDateis not after or equals to the given one.
-
isAfterOrEqualTo
Same assertion asisAfterOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01")).isAfterOrEqualTo("2000-01-01") .isAfterOrEqualTo("1999-12-31");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not after or equals to theLocalDatebuilt from given String.
-
isAfter
Verifies that the actualLocalDateis strictly after the given one.Example :
assertThat(parse("2000-01-01")).isAfter(parse("1999-12-31"));- Parameters:
other- the givenLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if otherLocalDateisnull.AssertionError- if the actualLocalDateis not strictly after the given one.
-
isAfter
Same assertion asisAfter(LocalDate)but theLocalDateis built from given a String that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid conversion assertThat(parse("2000-01-01")).isAfter("1999-12-31");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not strictly after theLocalDatebuilt from given String.
-
isEqualTo
Same assertion asAbstractAssert.isEqualTo(Object)(where Object is expected to beLocalDate) but here you passLocalDateString representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01")).isEqualTo("2000-01-01");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not equal to theLocalDatebuilt from given String.
-
isNotEqualTo
Same assertion asAbstractAssert.isNotEqualTo(Object)(where Object is expected to beLocalDate) but here you passLocalDateString representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String in comparison to avoid writing the code to perform the conversion assertThat(parse("2000-01-01")).isNotEqualTo("2000-01-15");- Parameters:
localDateAsString- String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis equal to theLocalDatebuilt from given String.
-
isIn
Same assertion asAbstractAssert.isIn(Object...)(where Objects are expected to beLocalDate) but here you passLocalDateString representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String based representation of LocalDate assertThat(parse("2000-01-01")).isIn("1999-12-31", "2000-01-01");- Parameters:
localDatesAsString- String array representingLocalDates.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis not in theLocalDates built from given Strings.
-
isNotIn
Same assertion asAbstractAssert.isNotIn(Object...)(where Objects are expected to beLocalDate) but here you passLocalDateString representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example :
// use String based representation of LocalDate assertThat(parse("2000-01-01")).isNotIn("1999-12-31", "2000-01-02");- Parameters:
localDatesAsString- Array of String representing aLocalDate.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.IllegalArgumentException- if given String is null or can't be converted to aLocalDate.AssertionError- if the actualLocalDateis in theLocalDates built from given Strings.
-
isInThePast
Verifies that the actualLocalDateis strictly in the past.Example:
// assertion succeeds: assertThat(LocalDate.now().minusDays(1)).isInThePast();- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not in the past.- Since:
- 3.25.0
-
isToday
Verifies that the actualLocalDateis today, that is matching current year, month and day.Example:
// assertion succeeds: assertThat(LocalDate.now()).isToday(); // assertion will fail assertThat(theFellowshipOfTheRing.getReleaseDate()).isToday();- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not today.
-
isInTheFuture
Verifies that the actualLocalDateis strictly in the future.Example:
// assertion succeeds: assertThat(LocalDate.now().plusDays(1)).isInTheFuture();- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not in the future.- Since:
- 3.25.0
-
isBetween
Verifies that the actualLocalDateis in the [start, end] period (start and end included).Example:
LocalDate localDate = LocalDate.now(); // assertions succeed: assertThat(localDate).isBetween(localDate.minusDays(1), localDate.plusDays(1)) .isBetween(localDate, localDate.plusDays(1)) .isBetween(localDate.minusDays(1), localDate) .isBetween(localDate, localDate); // assertions fail: assertThat(localDate).isBetween(localDate.minusDays(10), localDate.minusDays(1)); assertThat(localDate).isBetween(localDate.plusDays(1), localDate.plusDays(10));- Parameters:
startInclusive- the start value (inclusive), expected not to be null.endInclusive- the end value (inclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.AssertionError- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isBetween
Same assertion asisBetween(LocalDate, LocalDate)but here you passLocalDateString representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example:
LocalDate firstOfJanuary2000 = LocalDate.parse("2000-01-01"); // assertions succeed: assertThat(firstOfJanuary2000).isBetween("1999-01-01", "2001-01-01") .isBetween("2000-01-01", "2001-01-01") .isBetween("1999-01-01", "2000-01-01") .isBetween("2000-01-01", "2000-01-01"); // assertion fails: assertThat(firstOfJanuary2000).isBetween("1999-01-01", "1999-12-31");- Parameters:
startInclusive- the start value (inclusive), expected not to be null.endInclusive- the end value (inclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.DateTimeParseException- if any of the given String can't be converted to aLocalDate.AssertionError- if the actual value is not in [start, end] period.- Since:
- 3.7.1
-
isStrictlyBetween
Verifies that the actualLocalDateis in the ]start, end[ period (start and end excluded).Example:
LocalDate localDate = LocalDate.now(); // assertion succeeds: assertThat(localDate).isStrictlyBetween(localDate.minusDays(1), localDate.plusDays(1)); // assertions fail: assertThat(localDate).isStrictlyBetween(localDate.minusDays(10), localDate.minusDays(1)); assertThat(localDate).isStrictlyBetween(localDate.plusDays(1), localDate.plusDays(10)); assertThat(localDate).isStrictlyBetween(localDate, localDate.plusDays(1)); assertThat(localDate).isStrictlyBetween(localDate.minusDays(1), localDate);- Parameters:
startExclusive- the start value (exclusive), expected not to be null.endExclusive- the end value (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.AssertionError- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
isStrictlyBetween
Same assertion asisStrictlyBetween(LocalDate, LocalDate)but here you passLocalDateString representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.Example:
LocalDate firstOfJanuary2000 = LocalDate.parse("2000-01-01"); // assertion succeeds: assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "2001-01-01"); // assertions fail: assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "1999-12-31"); assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01", "2001-01-01"); assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "2000-01-01");- Parameters:
startExclusive- the start value (exclusive), expected not to be null.endExclusive- the end value (exclusive), expected not to be null.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actual value isnull.NullPointerException- if start value isnull.NullPointerException- if end value isnull.DateTimeParseException- if any of the given String can't be converted to aLocalDate.AssertionError- if the actual value is not in ]start, end[ period.- Since:
- 3.7.1
-
hasYear
Verifies that actualLocalDateis in the given year.Example:
// Assertion succeeds: assertThat(LocalDate.of(2000, 12, 31)).hasYear(2000); // Assertion fails: assertThat(LocalDate.of(2000, 12, 31)).hasYear(2001);- Parameters:
year- the given year.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not in the given year.- Since:
- 3.23.0
-
hasMonth
Verifies that actualLocalDateis in the given month.Example:
// Assertion succeeds: assertThat(LocalDate.of(2000, 12, 31)).hasMonth(Month.DECEMBER); // Assertion fails: assertThat(LocalDate.of(2000, 12, 31)).hasMonth(Month.JANUARY);- Parameters:
month- the givenMonth.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not in the given month.- Since:
- 3.23.0
-
hasMonthValue
Verifies that actualLocalDateis in the given month.Example:
// Assertion succeeds: assertThat(LocalDate.of(2000, 12, 31)).hasMonthValue(12); // Assertion fails: assertThat(LocalDate.of(2000, 12, 31)).hasMonthValue(11);- Parameters:
month- the given month's value between 1 and 12 inclusive.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not in the given month.- Since:
- 3.23.0
-
hasDayOfMonth
Verifies that actualLocalDateis on the given day.Example:
// Assertion succeeds: assertThat(LocalDate.of(2000, 12, 31)).hasDayOfMonth(31); // Assertion fails: assertThat(LocalDate.of(2000, 12, 31)).hasDayOfMonth(1);- Parameters:
day- the given numeric day.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualLocalDateisnull.AssertionError- if the actualLocalDateis not on the given day.- Since:
- 3.23.0
-
parse
Obtains an instance ofTEMPORALfrom a string representation in ISO date format.- Specified by:
parsein classAbstractTemporalAssert<SELF extends AbstractLocalDateAssert<SELF>,LocalDate> - Parameters:
localDateAsString- the string to parse, not null- Returns:
- the parsed
TEMPORAL, not null
-