Package org.assertj.core.api
Class AbstractLocalDateAssert<SELF extends AbstractLocalDateAssert<SELF>>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,TEMPORAL>
-
- 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 forLocalDatetype from new Date & Time API introduced in Java 8.
-
-
Field Summary
Fields Modifier and Type Field Description static StringNULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE-
Fields inherited from class org.assertj.core.api.AbstractTemporalAssert
comparables
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, info, myself, objects, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLocalDateAssert(LocalDate actual, Class<?> selfType)Creates a new.AbstractLocalDateAssert
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidassertLocalDateAsStringParameterIsNotNull(String localDateAsString)Check that theLocalDatestring representation to compare actualLocalDateto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit messageprivate static voidassertLocalDateParameterIsNotNull(LocalDate other)Check that theLocalDateto compare actualLocalDateto is not null, in that case throws aIllegalArgumentExceptionwith an explicit messageprivate voidcheckIsNotNullAndNotEmpty(Object[] values)private static Object[]convertToLocalDateArray(String... localDatesAsString)SELFisAfter(String localDateAsString)Same assertion asisAfter(LocalDate)but theLocalDateis built from given a String that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.SELFisAfter(LocalDate other)Verifies that the actualLocalDateis strictly after the given one.SELFisAfterOrEqualTo(String localDateAsString)Same assertion asisAfterOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.SELFisAfterOrEqualTo(LocalDate other)Verifies that the actualLocalDateis after or equals to the given one.SELFisBefore(String localDateAsString)Same assertion asisBefore(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.SELFisBefore(LocalDate other)Verifies that the actualLocalDateis strictly before the given one.SELFisBeforeOrEqualTo(String localDateAsString)Same assertion asisBeforeOrEqualTo(LocalDate)but theLocalDateis built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.SELFisBeforeOrEqualTo(LocalDate other)Verifies that the actualLocalDateis before or equals to the given one.SELFisBetween(String startInclusive, String endInclusive)Same assertion asisBetween(LocalDate, LocalDate)but here you passLocalDateString representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)method.SELFisBetween(LocalDate startInclusive, LocalDate endInclusive)Verifies that the actualLocalDateis in the [start, end] period (start and end included).SELFisEqualTo(String localDateAsString)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.SELFisIn(String... localDatesAsString)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.SELFisNotEqualTo(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.SELFisNotIn(String... localDatesAsString)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.SELFisStrictlyBetween(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.SELFisStrictlyBetween(LocalDate startExclusive, LocalDate endExclusive)Verifies that the actualLocalDateis in the ]start, end[ period (start and end excluded).SELFisToday()Verifies that the actualLocalDateis today, that is matching current year, month and day.protected LocalDateparse(String localDateAsString)Obtains an instance ofTEMPORALfrom a string representation in ISO date format.-
Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
getActual, isCloseTo, isCloseTo
-
Methods inherited from class org.assertj.core.api.AbstractAssert
as, as, asInstanceOf, 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, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withAssertionState, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Field Detail
-
NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
public static final String NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractLocalDateAssert
protected AbstractLocalDateAssert(LocalDate actual, Class<?> selfType)
Creates a new.AbstractLocalDateAssert- Parameters:
selfType- the "self type"actual- the actual value to verify
-
-
Method Detail
-
isBefore
public SELF isBefore(LocalDate other)
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
public SELF isBefore(String localDateAsString)
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
public SELF isBeforeOrEqualTo(LocalDate other)
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
public SELF 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.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
public SELF isAfterOrEqualTo(LocalDate other)
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
public SELF 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.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
public SELF isAfter(LocalDate other)
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
public SELF isAfter(String localDateAsString)
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
public SELF isEqualTo(String localDateAsString)
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
public SELF 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.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
public SELF isIn(String... localDatesAsString)
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
public SELF isNotIn(String... localDatesAsString)
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.
-
isToday
public SELF isToday()
Verifies that the actualLocalDateis today, that is matching current year, month and day.Example:
// assertion will pass 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.
-
isBetween
public SELF isBetween(LocalDate startInclusive, LocalDate endInclusive)
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
public SELF isBetween(String startInclusive, String endInclusive)
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
public SELF isStrictlyBetween(LocalDate startExclusive, LocalDate endExclusive)
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
public SELF 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.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
-
parse
protected LocalDate parse(String localDateAsString)
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
-
convertToLocalDateArray
private static Object[] convertToLocalDateArray(String... localDatesAsString)
-
checkIsNotNullAndNotEmpty
private void checkIsNotNullAndNotEmpty(Object[] values)
-
assertLocalDateAsStringParameterIsNotNull
private static void assertLocalDateAsStringParameterIsNotNull(String localDateAsString)
Check that theLocalDatestring representation to compare actualLocalDateto is not null, otherwise throws aIllegalArgumentExceptionwith an explicit message- Parameters:
localDateAsString- String representing theLocalDateto compare actual with- Throws:
IllegalArgumentException- with an explicit message if the givenStringis null
-
assertLocalDateParameterIsNotNull
private static void assertLocalDateParameterIsNotNull(LocalDate other)
Check that theLocalDateto compare actualLocalDateto is not null, in that case throws aIllegalArgumentExceptionwith an explicit message- Parameters:
other- theLocalDateto check- Throws:
IllegalArgumentException- with an explicit message if the givenLocalDateis null
-
-