Class AbstractInstantAssert<SELF extends AbstractInstantAssert<SELF>>

    • Constructor Detail

      • AbstractInstantAssert

        protected AbstractInstantAssert​(Instant actual,
                                        Class<?> selfType)
        Creates a new AbstractInstantAssert.
        Parameters:
        selfType - the "self type"
        actual - the actual value to verify
    • Method Detail

      • isBefore

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

        Example :

         assertThat(parse("2007-12-03T10:15:30.00Z")).isBefore(parse("2007-12-03T10:15:31.00Z"));
        Parameters:
        other - the given Instant.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual Instant is null.
        IllegalArgumentException - if other Instant is null.
        AssertionError - if the actual Instant is not strictly before the given one.
        Since:
        3.7.0
      • isBeforeOrEqualTo

        public SELF isBeforeOrEqualTo​(Instant other)
        Verifies that the actual Instant is before or equals to the given one.

        Example :

         assertThat(parse("2007-12-03T10:15:30.00Z")).isBeforeOrEqualTo(parse("2007-12-03T10:15:30.00Z"))
                                        .isBeforeOrEqualTo(parse("2007-12-03T10:15:31.00Z"));
        Parameters:
        other - the given Instant.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual Instant is null.
        IllegalArgumentException - if other Instant is null.
        AssertionError - if the actual Instant is not before or equals to the given one.
        Since:
        3.7.0
      • isAfterOrEqualTo

        public SELF isAfterOrEqualTo​(Instant other)
        Verifies that the actual Instant is after or equals to the given one.

        Example :

         assertThat(parse("2007-12-03T10:15:30.00Z")).isAfterOrEqualTo(parse("2007-12-03T10:15:30.00Z"))
                                        .isAfterOrEqualTo(parse("2007-12-03T10:15:27.00Z"));
        Parameters:
        other - the given Instant.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual Instant is null.
        IllegalArgumentException - if other Instant is null.
        AssertionError - if the actual Instant is not after or equals to the given one.
        Since:
        3.7.0
      • isAfter

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

        Example :

         assertThat(parse("2007-12-03T10:15:30.00Z").isAfter(parse("2007-12-03T10:15:27.00Z"));
        Parameters:
        other - the given Instant.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual Instant is null.
        IllegalArgumentException - if other Instant is null.
        AssertionError - if the actual Instant is not strictly after the given one.
        Since:
        3.7.0
      • isBetween

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

        Example:

         Instant instant = Instant.now();
        
         // assertions succeed:
         assertThat(instant).isBetween(instant.minusSeconds(1), instant.plusSeconds(1))
                            .isBetween(instant, instant.plusSeconds(1))
                            .isBetween(instant.minusSeconds(1), instant)
                            .isBetween(instant, instant);
        
         // assertions fail:
         assertThat(instant).isBetween(instant.minusSeconds(10), instant.minusSeconds(1));
         assertThat(instant).isBetween(instant.plusSeconds(1), instant.plusSeconds(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] range.
        Since:
        3.7.1
      • isBetween

        public SELF isBetween​(String startInclusive,
                              String endInclusive)
        Same assertion as isBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant.parse(CharSequence) method.

        Example:

         Instant firstOfJanuary2000 = Instant.parse("2000-01-01T00:00:00.00Z");
        
         // assertions succeed:
         assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z")
                                       .isBetween("2000-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z")
                                       .isBetween("1999-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z")
                                       .isBetween("2000-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z");
        
         // assertion fails:
         assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:00.00Z", "1999-12-31T23:59:59.59Z");
        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 Instant.
        AssertionError - if the actual value is not in [start, end] range.
        Since:
        3.7.1
      • isStrictlyBetween

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

        Example:

         Instant instant = Instant.now();
        
         // assertion succeeds:
         assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant.plusSeconds(1));
        
         // assertions fail:
         assertThat(instant).isStrictlyBetween(instant.minusSeconds(10), instant.minusSeconds(1));
         assertThat(instant).isStrictlyBetween(instant.plusSeconds(1), instant.plusSeconds(10));
         assertThat(instant).isStrictlyBetween(instant, instant.plusSeconds(1));
         assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant);
        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[ range.
        Since:
        3.7.1
      • isStrictlyBetween

        public SELF isStrictlyBetween​(String startExclusive,
                                      String endExclusive)
        Same assertion as isStrictlyBetween(Instant, Instant) but here you pass Instant String representations that must follow ISO Instant format to allow calling Instant.parse(CharSequence) method.

        Example:

         Instant firstOfJanuary2000 = Instant.parse("2000-01-01T00:00:00.00Z");
        
         // assertion succeeds:
         assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z");
        
         // assertions fail:
         assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "1999-12-31T23:59:59.59Z");
         assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00.00Z", "2001-01-01T00:00:00.00Z");
         assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:00.00Z", "2000-01-01T00:00:00.00Z");
        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 Instant.
        AssertionError - if the actual value is not in ]start, end[ range.
        Since:
        3.7.1
      • convertToInstantArray

        private static Object[] convertToInstantArray​(String[] instantsAsString)
      • checkIsNotNullAndNotEmpty

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

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

        private static void assertInstantParameterIsNotNull​(Instant instant)