Class AbstractYearMonthAssert<SELF extends AbstractYearMonthAssert<SELF>>

Type Parameters:
SELF - the "self" type of this assertion class.
All Implemented Interfaces:
Assert<SELF,YearMonth>, Descriptable<SELF>, ExtensionPoints<SELF,YearMonth>
Direct Known Subclasses:
YearMonthAssert

public abstract class AbstractYearMonthAssert<SELF extends AbstractYearMonthAssert<SELF>> extends AbstractTemporalAssert<SELF,YearMonth>
Base class for all implementations of assertions for YearMonth type from new Date & Time API introduced in Java 8.
Since:
3.26.0
  • Constructor Details

    • AbstractYearMonthAssert

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

    • isBefore

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

      Example:

       assertThat(YearMonth.of(2000, 1)).isBefore(YearMonth.of(2000, 2));
      Parameters:
      other - the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if other YearMonth is null.
      AssertionError - if the actual YearMonth is not strictly before the given one.
    • isBefore

      public SELF isBefore(String otherYearMonthAsString)
      Verifies that the actual YearMonth is strictly before the given one.

      Same assertion as isBefore(YearMonth) but the YearMonth is built from the given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isBefore("2000-02");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not strictly before the YearMonth built from given string.
    • isBeforeOrEqualTo

      public SELF isBeforeOrEqualTo(YearMonth other)
      Verifies that the actual YearMonth is before or equal to the given one.

      Example:

       assertThat(YearMonth.of(2000, 1)).isBeforeOrEqualTo(YearMonth.of(2000, 1))
                                        .isBeforeOrEqualTo(YearMonth.of(2000, 2));
      Parameters:
      other - the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if other YearMonth is null.
      AssertionError - if the actual YearMonth is not before or equal to the given one.
    • isBeforeOrEqualTo

      public SELF isBeforeOrEqualTo(String otherYearMonthAsString)
      Verifies that the actual YearMonth is before or equal to the given one.

      Same assertion as isBeforeOrEqualTo(YearMonth) but the YearMonth is built from given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isBeforeOrEqualTo("2000-01")
                                        .isBeforeOrEqualTo("2000-02");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not before or equal to the YearMonth built from given string.
    • isAfterOrEqualTo

      public SELF isAfterOrEqualTo(YearMonth other)
      Verifies that the actual YearMonth is after or equal to the given one.

      Example:

       assertThat(YearMonth.of(2000, 1)).isAfterOrEqualTo(YearMonth.of(2000, 1))
                                        .isAfterOrEqualTo(parse("1999-12"));
      Parameters:
      other - the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if other YearMonth is null.
      AssertionError - if the actual YearMonth is not after or equal to the given one.
    • isAfterOrEqualTo

      public SELF isAfterOrEqualTo(String otherYearMonthAsString)
      Verifies that the actual YearMonth is after or equal to the given one.

      Same assertion as isAfterOrEqualTo(YearMonth) but the YearMonth is built from given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isAfterOrEqualTo("2000-01")
                                        .isAfterOrEqualTo("1999-12");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not after or equal to the YearMonth built from given string.
    • isAfter

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

      Example:

       assertThat(YearMonth.of(2000, 1)).isAfter(parse("1999-12"));
      Parameters:
      other - the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if other YearMonth is null.
      AssertionError - if the actual YearMonth is not strictly after the given one.
    • isAfter

      public SELF isAfter(String otherYearMonthAsString)
      Verifies that the actual YearMonth is strictly after the given one.

      Same assertion as isAfter(YearMonth) but the YearMonth is built from given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isAfter("1999-12");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not strictly after the YearMonth built from given string.
    • isEqualTo

      public SELF isEqualTo(String otherYearMonthAsString)
      Verifies that the actual YearMonth is equal to the given one.

      Same assertion as AbstractAssert.isEqualTo(Object) but the YearMonth is built from given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isEqualTo("2000-01");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not equal to the YearMonth built from given string.
    • isNotEqualTo

      public SELF isNotEqualTo(String otherYearMonthAsString)
      Verifies that the actual YearMonth is not equal to the given one.

      Same assertion as AbstractAssert.isNotEqualTo(Object) but the YearMonth is built from given string, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isNotEqualTo("2000-02");
      Parameters:
      otherYearMonthAsString - string representation of the other YearMonth to compare to, not null.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if the given string is null.
      DateTimeParseException - if the given string cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is equal to the YearMonth built from given string.
    • isIn

      public SELF isIn(String... otherYearMonthsAsString)
      Verifies that the actual YearMonth is present in the given array of values.

      Same assertion as AbstractAssert.isIn(Object...) but the YearMonths are built from given strings, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isIn("1999-12", "2000-01");
      Parameters:
      otherYearMonthsAsString - string array representing YearMonths.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if any of the given strings is null.
      DateTimeParseException - if any of the given strings cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is not in the YearMonths built from given strings.
    • isNotIn

      public SELF isNotIn(String... otherYearMonthsAsString)
      Verifies that the actual YearMonth is not present in the given array of values.

      Same assertion as AbstractAssert.isNotIn(Object...) but the YearMonths are built from given strings, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       // use string representation of YearMonth
       assertThat(YearMonth.of(2000, 1)).isNotIn("1999-12", "2000-02");
      Parameters:
      otherYearMonthsAsString - Array of string representing a YearMonth.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      IllegalArgumentException - if any of the given strings is null.
      DateTimeParseException - if any of the given strings cannot be parsed to a YearMonth.
      AssertionError - if the actual YearMonth is in the YearMonths built from given strings.
    • isInThePast

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

      Example:

       // assertion succeeds:
       assertThat(YearMonth.now().minusMonths(1)).isInThePast();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      AssertionError - if the actual YearMonth is not in the past.
    • isCurrentYearMonth

      public SELF isCurrentYearMonth()
      Verifies that the actual YearMonth is the current YearMonth.

      Example:

       // assertion succeeds:
       assertThat(YearMonth.now()).isCurrentYearMonth();
      
       // assertion fails:
       assertThat(theFellowshipOfTheRing.getReleaseDate()).isCurrentYearMonth();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      AssertionError - if the actual YearMonth is not the current YearMonth.
    • isInTheFuture

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

      Example:

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

      public SELF isBetween(YearMonth startInclusive, YearMonth endInclusive)
      Verifies that the actual YearMonth is in the [start, end] period (start and end included).

      Example:

       YearMonth yearMonth = YearMonth.now();
      
       // assertions succeed:
       assertThat(yearMonth).isBetween(yearMonth.minusMonths(1), yearMonth.plusMonths(1))
                            .isBetween(yearMonth, yearMonth.plusMonths(1))
                            .isBetween(yearMonth.minusMonths(1), yearMonth)
                            .isBetween(yearMonth, yearMonth);
      
       // assertions fail:
       assertThat(yearMonth).isBetween(yearMonth.minusMonths(10), yearMonth.minusMonths(1));
       assertThat(yearMonth).isBetween(yearMonth.plusMonths(1), yearMonth.plusMonths(10));
      Parameters:
      startInclusive - the start value (inclusive), not null.
      endInclusive - the end value (inclusive), not 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.
    • isBetween

      public SELF isBetween(String startInclusive, String endInclusive)
      Verifies that the actual YearMonth is in the [start, end] period (start and end included).

      Same assertion as isBetween(YearMonth, YearMonth) but the YearMonths are built from given strings, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       YearMonth january2000 = YearMonth.parse("2000-01");
      
       // assertions succeed:
       assertThat(january2000).isBetween("1999-01", "2001-01")
                              .isBetween("2000-01", "2001-01")
                              .isBetween("1999-01", "2000-01")
                              .isBetween("2000-01", "2000-01");
      
       // assertion fails:
       assertThat(january2000).isBetween("1999-01", "1999-12");
      Parameters:
      startInclusive - the start value (inclusive), not null.
      endInclusive - the end value (inclusive), not 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 YearMonth.
      AssertionError - if the actual value is not in [start, end] period.
    • isStrictlyBetween

      public SELF isStrictlyBetween(YearMonth startExclusive, YearMonth endExclusive)
      Verifies that the actual YearMonth is in the ]start, end[ period (start and end excluded).

      Example:

       YearMonth yearMonth = YearMonth.now();
      
       // assertion succeeds:
       assertThat(yearMonth).isStrictlyBetween(yearMonth.minusMonths(1), yearMonth.plusMonths(1));
      
       // assertions fail:
       assertThat(yearMonth).isStrictlyBetween(yearMonth.minusMonths(10), yearMonth.minusMonths(1));
       assertThat(yearMonth).isStrictlyBetween(yearMonth.plusMonths(1), yearMonth.plusMonths(10));
       assertThat(yearMonth).isStrictlyBetween(yearMonth, yearMonth.plusMonths(1));
       assertThat(yearMonth).isStrictlyBetween(yearMonth.minusMonths(1), yearMonth);
      Parameters:
      startExclusive - the start value (exclusive), not null.
      endExclusive - the end value (exclusive), not 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.
    • isStrictlyBetween

      public SELF isStrictlyBetween(String startExclusive, String endExclusive)
      Verifies that the actual YearMonth is in the ]start, end[ period (start and end excluded).

      Same assertion as isStrictlyBetween(YearMonth, YearMonth) but the YearMonths are built from given strings, which must follow the DateTimeFormatter pattern uuuu-MM to allow calling YearMonth.parse(CharSequence) method.

      Example:

       YearMonth january2000 = YearMonth.parse("2000-01");
      
       // assertion succeeds:
       assertThat(january2000).isStrictlyBetween("1999-01", "2001-01");
      
       // assertions fail:
       assertThat(january2000).isStrictlyBetween("1999-01", "1999-12");
       assertThat(january2000).isStrictlyBetween("2000-01", "2001-01");
       assertThat(january2000).isStrictlyBetween("1999-01", "2000-01");
      Parameters:
      startExclusive - the start value (exclusive), not null.
      endExclusive - the end value (exclusive), not 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 YearMonth.
      AssertionError - if the actual value is not in ]start, end[ period.
    • hasYear

      public SELF hasYear(int year)
      Verifies that the actual YearMonth is in the given year.

      Example:

       // assertion succeeds:
       assertThat(YearMonth.of(2000, 12)).hasYear(2000);
      
       // assertion fails:
       assertThat(YearMonth.of(2000, 12)).hasYear(2001);
      Parameters:
      year - the given year.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      AssertionError - if the actual YearMonth is not in the given year.
    • hasMonth

      public SELF hasMonth(Month month)
      Verifies that the actual YearMonth is in the given month.

      Example:

       // assertion succeeds:
       assertThat(YearMonth.of(2000, 12)).hasMonth(Month.DECEMBER);
      
       // assertion fails:
       assertThat(YearMonth.of(2000, 12)).hasMonth(Month.JANUARY);
      Parameters:
      month - the given Month.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      AssertionError - if the actual YearMonth is not in the given month.
    • hasMonthValue

      public SELF hasMonthValue(int month)
      Verifies that the actual YearMonth is in the given month.

      Example:

       // assertion succeeds:
       assertThat(YearMonth.of(2000, 12)).hasMonthValue(12);
      
       // assertion fails:
       assertThat(YearMonth.of(2000, 12)).hasMonthValue(11);
      Parameters:
      month - the given month's value between 1 and 12 inclusive.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual YearMonth is null.
      AssertionError - if the actual YearMonth is not in the given month.
    • parse

      protected YearMonth parse(String yearMonthAsString)
      Obtains an instance of YearMonth from a text string such as 2007-12.
      Specified by:
      parse in class AbstractTemporalAssert<SELF extends AbstractYearMonthAssert<SELF>,YearMonth>
      Parameters:
      yearMonthAsString - the string to parse, not null
      Returns:
      the parsed TEMPORAL, not null
      See Also:
    • assertYearMonthParameterIsNotNull

      private static void assertYearMonthParameterIsNotNull(YearMonth other)
      Check that the YearMonth to compare actual YearMonth to is not null, in that case throws a IllegalArgumentException with an explicit message.
      Parameters:
      other - the YearMonth to check.
      Throws:
      IllegalArgumentException - with an explicit message if the given YearMonth is null.
    • assertYearMonthAsStringParameterIsNotNull

      private static void assertYearMonthAsStringParameterIsNotNull(String otherYearMonthAsString)
      Check that the YearMonth string representation to compare actual YearMonth to is not null, otherwise throws a IllegalArgumentException with an explicit message.
      Parameters:
      otherYearMonthAsString - string representing the YearMonth to compare actual with.
      Throws:
      IllegalArgumentException - with an explicit message if the given String is null.
    • checkIsNotNullAndNotEmpty

      private static void checkIsNotNullAndNotEmpty(Object[] values)
    • convertToYearMonthArray

      private static Object[] convertToYearMonthArray(String... yearMonthsAsString)