Class AbstractLocalDateAssert<SELF extends 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 Details

    • NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE

      public static final String NULL_LOCAL_DATE_TIME_PARAMETER_MESSAGE
      See Also:
  • Constructor Details

    • AbstractLocalDateAssert

      protected AbstractLocalDateAssert(LocalDate actual, Class<?> selfType)
      Parameters:
      actual - the actual value to verify
      selfType - the "self type"
  • Method Details

    • isBefore

      public SELF isBefore(LocalDate other)
      Verifies that the actual LocalDate is strictly before the given one.

      Example :

       assertThat(parse("2000-01-01")).isBefore(parse("2000-01-02"));
      Parameters:
      other - the given LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if other LocalDate is null.
      AssertionError - if the actual LocalDate is not strictly before the given one.
    • isBefore

      public SELF isBefore(String localDateAsString)
      Same assertion as isBefore(LocalDate) but the LocalDate is built from given String, which must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not strictly before the LocalDate built from given String.
    • isBeforeOrEqualTo

      public SELF isBeforeOrEqualTo(LocalDate other)
      Verifies that the actual LocalDate 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 given LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if other LocalDate is null.
      AssertionError - if the actual LocalDate is not before or equals to the given one.
    • isBeforeOrEqualTo

      public SELF isBeforeOrEqualTo(String localDateAsString)
      Same assertion as isBeforeOrEqualTo(LocalDate) but the LocalDate is built from given String, which must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not before or equals to the LocalDate built from given String.
    • isAfterOrEqualTo

      public SELF isAfterOrEqualTo(LocalDate other)
      Verifies that the actual LocalDate 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 given LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if other LocalDate is null.
      AssertionError - if the actual LocalDate is not after or equals to the given one.
    • isAfterOrEqualTo

      public SELF isAfterOrEqualTo(String localDateAsString)
      Same assertion as isAfterOrEqualTo(LocalDate) but the LocalDate is built from given String, which must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not after or equals to the LocalDate built from given String.
    • isAfter

      public SELF isAfter(LocalDate other)
      Verifies that the actual LocalDate is strictly after the given one.

      Example :

       assertThat(parse("2000-01-01")).isAfter(parse("1999-12-31"));
      Parameters:
      other - the given LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if other LocalDate is null.
      AssertionError - if the actual LocalDate is not strictly after the given one.
    • isAfter

      public SELF isAfter(String localDateAsString)
      Same assertion as isAfter(LocalDate) but the LocalDate is built from given a String that must follow ISO LocalDate format to allow calling LocalDate.parse(CharSequence) method.

      Example :

       // use String in comparison to avoid conversion
       assertThat(parse("2000-01-01")).isAfter("1999-12-31");
      Parameters:
      localDateAsString - String representing a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not strictly after the LocalDate built from given String.
    • isEqualTo

      public SELF isEqualTo(String localDateAsString)
      Same assertion as AbstractAssert.isEqualTo(Object) (where Object is expected to be LocalDate) but here you pass LocalDate String representation that must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not equal to the LocalDate built from given String.
    • isNotEqualTo

      public SELF isNotEqualTo(String localDateAsString)
      Same assertion as AbstractAssert.isNotEqualTo(Object) (where Object is expected to be LocalDate) but here you pass LocalDate String representation that must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is equal to the LocalDate built from given String.
    • isIn

      public SELF isIn(String... localDatesAsString)
      Same assertion as AbstractAssert.isIn(Object...) (where Objects are expected to be LocalDate) but here you pass LocalDate String representations that must follow ISO LocalDate format to allow calling LocalDate.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 representing LocalDates.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is not in the LocalDates built from given Strings.
    • isNotIn

      public SELF isNotIn(String... localDatesAsString)
      Same assertion as AbstractAssert.isNotIn(Object...) (where Objects are expected to be LocalDate) but here you pass LocalDate String representations that must follow ISO LocalDate format to allow calling LocalDate.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 a LocalDate.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      IllegalArgumentException - if given String is null or can't be converted to a LocalDate.
      AssertionError - if the actual LocalDate is in the LocalDates built from given Strings.
    • isInThePast

      public SELF isInThePast()
      Verifies that the actual LocalDate is strictly in the past.

      Example:

       // assertion succeeds:
       assertThat(LocalDate.now().minusDays(1)).isInThePast();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      AssertionError - if the actual LocalDate is not in the past.
      Since:
      3.25.0
    • isToday

      public SELF isToday()
      Verifies that the actual LocalDate is 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 actual LocalDate is null.
      AssertionError - if the actual LocalDate is not today.
    • isInTheFuture

      public SELF isInTheFuture()
      Verifies that the actual LocalDate is strictly in the future.

      Example:

       // assertion succeeds:
       assertThat(LocalDate.now().plusDays(1)).isInTheFuture();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      AssertionError - if the actual LocalDate is not in the future.
      Since:
      3.25.0
    • isBetween

      public SELF isBetween(LocalDate startInclusive, LocalDate endInclusive)
      Verifies that the actual LocalDate 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 is null.
      NullPointerException - if start value is null.
      NullPointerException - if end value is null.
      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 as isBetween(LocalDate, LocalDate) but here you pass LocalDate String representations which must follow ISO LocalDate format to allow calling LocalDate.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 is null.
      NullPointerException - if start value is null.
      NullPointerException - if end value is null.
      DateTimeParseException - if any of the given String can't be converted to a LocalDate.
      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 actual LocalDate 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 is null.
      NullPointerException - if start value is null.
      NullPointerException - if end value is null.
      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 as isStrictlyBetween(LocalDate, LocalDate) but here you pass LocalDate String representations which must follow ISO LocalDate format to allow calling LocalDate.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 is null.
      NullPointerException - if start value is null.
      NullPointerException - if end value is null.
      DateTimeParseException - if any of the given String can't be converted to a LocalDate.
      AssertionError - if the actual value is not in ]start, end[ period.
      Since:
      3.7.1
    • hasYear

      public SELF hasYear(int year)
      Verifies that actual LocalDate is 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 actual LocalDate is null.
      AssertionError - if the actual LocalDate is not in the given year.
      Since:
      3.23.0
    • hasMonth

      public SELF hasMonth(Month month)
      Verifies that actual LocalDate is 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 given Month.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual LocalDate is null.
      AssertionError - if the actual LocalDate is not in the given month.
      Since:
      3.23.0
    • hasMonthValue

      public SELF hasMonthValue(int month)
      Verifies that actual LocalDate is 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 actual LocalDate is null.
      AssertionError - if the actual LocalDate is not in the given month.
      Since:
      3.23.0
    • hasDayOfMonth

      public SELF hasDayOfMonth(int day)
      Verifies that actual LocalDate is 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 actual LocalDate is null.
      AssertionError - if the actual LocalDate is not on the given day.
      Since:
      3.23.0
    • parse

      protected LocalDate parse(String localDateAsString)
      Obtains an instance of TEMPORAL from a string representation in ISO date format.
      Specified by:
      parse in class AbstractTemporalAssert<SELF extends AbstractLocalDateAssert<SELF>,LocalDate>
      Parameters:
      localDateAsString - the string to parse, not null
      Returns:
      the parsed TEMPORAL, not null