Class AbstractLocalDateAssert<SELF extends AbstractLocalDateAssert<SELF>>

    • 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)
        Parameters:
        selfType - the "self type"
        actual - the actual value to verify
    • Method Detail

      • 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.
      • 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.
      • 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.
      • 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.
      • isToday

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

        private static Object[] convertToLocalDateArray​(String... localDatesAsString)
      • checkIsNotNullAndNotEmpty

        private void checkIsNotNullAndNotEmpty​(Object[] values)
      • assertLocalDateAsStringParameterIsNotNull

        private static void assertLocalDateAsStringParameterIsNotNull​(String localDateAsString)
        Check that the LocalDate string representation to compare actual LocalDate to is not null, otherwise throws a IllegalArgumentException with an explicit message
        Parameters:
        localDateAsString - String representing the LocalDate to compare actual with
        Throws:
        IllegalArgumentException - with an explicit message if the given String is null