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 forLocalDate
type from new Date & Time API introduced in Java 8.
-
-
Field Summary
Fields Modifier and Type Field Description static String
NULL_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 protected
AbstractLocalDateAssert(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 void
assertLocalDateAsStringParameterIsNotNull(String localDateAsString)
Check that theLocalDate
string representation to compare actualLocalDate
to is not null, otherwise throws aIllegalArgumentException
with an explicit messageprivate static void
assertLocalDateParameterIsNotNull(LocalDate other)
Check that theLocalDate
to compare actualLocalDate
to is not null, in that case throws aIllegalArgumentException
with an explicit messageprivate void
checkIsNotNullAndNotEmpty(Object[] values)
private static Object[]
convertToLocalDateArray(String... localDatesAsString)
SELF
isAfter(String localDateAsString)
Same assertion asisAfter(LocalDate)
but theLocalDate
is built from given a String that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isAfter(LocalDate other)
Verifies that the actualLocalDate
is strictly after the given one.SELF
isAfterOrEqualTo(String localDateAsString)
Same assertion asisAfterOrEqualTo(LocalDate)
but theLocalDate
is built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isAfterOrEqualTo(LocalDate other)
Verifies that the actualLocalDate
is after or equals to the given one.SELF
isBefore(String localDateAsString)
Same assertion asisBefore(LocalDate)
but theLocalDate
is built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isBefore(LocalDate other)
Verifies that the actualLocalDate
is strictly before the given one.SELF
isBeforeOrEqualTo(String localDateAsString)
Same assertion asisBeforeOrEqualTo(LocalDate)
but theLocalDate
is built from given String, which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isBeforeOrEqualTo(LocalDate other)
Verifies that the actualLocalDate
is before or equals to the given one.SELF
isBetween(String startInclusive, String endInclusive)
Same assertion asisBetween(LocalDate, LocalDate)
but here you passLocalDate
String representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isBetween(LocalDate startInclusive, LocalDate endInclusive)
Verifies that the actualLocalDate
is in the [start, end] period (start and end included).SELF
isEqualTo(String localDateAsString)
Same assertion asAbstractAssert.isEqualTo(Object)
(where Object is expected to beLocalDate
) but here you passLocalDate
String representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isIn(String... localDatesAsString)
Same assertion asAbstractAssert.isIn(Object...)
(where Objects are expected to beLocalDate
) but here you passLocalDate
String representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isNotEqualTo(String localDateAsString)
Same assertion asAbstractAssert.isNotEqualTo(Object)
(where Object is expected to beLocalDate
) but here you passLocalDate
String representation that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isNotIn(String... localDatesAsString)
Same assertion asAbstractAssert.isNotIn(Object...)
(where Objects are expected to beLocalDate
) but here you passLocalDate
String representations that must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isStrictlyBetween(String startExclusive, String endExclusive)
Same assertion asisStrictlyBetween(LocalDate, LocalDate)
but here you passLocalDate
String representations which must follow ISO LocalDate format to allow callingLocalDate.parse(CharSequence)
method.SELF
isStrictlyBetween(LocalDate startExclusive, LocalDate endExclusive)
Verifies that the actualLocalDate
is in the ]start, end[ period (start and end excluded).SELF
isToday()
Verifies that the actualLocalDate
is today, that is matching current year, month and day.protected LocalDate
parse(String localDateAsString)
Obtains an instance ofTEMPORAL
from a string representation in ISO date format.-
Methods inherited from class org.assertj.core.api.AbstractTemporalAssert
getActual, isCloseTo, isCloseTo, usingComparator, usingComparator, usingDefaultComparator
-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, extracting, extracting, failWithActualExpectedAndMessage, 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, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveComparison, usingRecursiveComparison, withAssertionState, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, describedAs
-
-
-
-
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 actualLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if otherLocalDate
isnull
.AssertionError
- if the actualLocalDate
is not strictly before the given one.
-
isBefore
public SELF isBefore(String localDateAsString)
Same assertion asisBefore(LocalDate)
but theLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not strictly before theLocalDate
built from given String.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(LocalDate other)
Verifies that the actualLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if otherLocalDate
isnull
.AssertionError
- if the actualLocalDate
is not before or equals to the given one.
-
isBeforeOrEqualTo
public SELF isBeforeOrEqualTo(String localDateAsString)
Same assertion asisBeforeOrEqualTo(LocalDate)
but theLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not before or equals to theLocalDate
built from given String.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(LocalDate other)
Verifies that the actualLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if otherLocalDate
isnull
.AssertionError
- if the actualLocalDate
is not after or equals to the given one.
-
isAfterOrEqualTo
public SELF isAfterOrEqualTo(String localDateAsString)
Same assertion asisAfterOrEqualTo(LocalDate)
but theLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not after or equals to theLocalDate
built from given String.
-
isAfter
public SELF isAfter(LocalDate other)
Verifies that the actualLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if otherLocalDate
isnull
.AssertionError
- if the actualLocalDate
is not strictly after the given one.
-
isAfter
public SELF isAfter(String localDateAsString)
Same assertion asisAfter(LocalDate)
but theLocalDate
is 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not strictly after theLocalDate
built from given String.
-
isEqualTo
public SELF isEqualTo(String localDateAsString)
Same assertion asAbstractAssert.isEqualTo(Object)
(where Object is expected to beLocalDate
) but here you passLocalDate
String 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not equal to theLocalDate
built from given String.
-
isNotEqualTo
public SELF isNotEqualTo(String localDateAsString)
Same assertion asAbstractAssert.isNotEqualTo(Object)
(where Object is expected to beLocalDate
) but here you passLocalDate
String 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is equal to theLocalDate
built from given String.
-
isIn
public SELF isIn(String... localDatesAsString)
Same assertion asAbstractAssert.isIn(Object...)
(where Objects are expected to beLocalDate
) but here you passLocalDate
String 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 representingLocalDate
s.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is not in theLocalDate
s built from given Strings.
-
isNotIn
public SELF isNotIn(String... localDatesAsString)
Same assertion asAbstractAssert.isNotIn(Object...)
(where Objects are expected to beLocalDate
) but here you passLocalDate
String 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 actualLocalDate
isnull
.IllegalArgumentException
- if given String is null or can't be converted to aLocalDate
.AssertionError
- if the actualLocalDate
is in theLocalDate
s built from given Strings.
-
isToday
public SELF isToday()
Verifies that the actualLocalDate
is 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 actualLocalDate
isnull
.AssertionError
- if the actualLocalDate
is not today.
-
isBetween
public SELF isBetween(LocalDate startInclusive, LocalDate endInclusive)
Verifies that the actualLocalDate
is 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 passLocalDate
String 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 actualLocalDate
is 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 passLocalDate
String 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 ofTEMPORAL
from a string representation in ISO date format.- Specified by:
parse
in 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 theLocalDate
string representation to compare actualLocalDate
to is not null, otherwise throws aIllegalArgumentException
with an explicit message- Parameters:
localDateAsString
- String representing theLocalDate
to compare actual with- Throws:
IllegalArgumentException
- with an explicit message if the givenString
is null
-
assertLocalDateParameterIsNotNull
private static void assertLocalDateParameterIsNotNull(LocalDate other)
Check that theLocalDate
to compare actualLocalDate
to is not null, in that case throws aIllegalArgumentException
with an explicit message- Parameters:
other
- theLocalDate
to check- Throws:
IllegalArgumentException
- with an explicit message if the givenLocalDate
is null
-
-