Class AbstractOffsetTimeAssert<SELF extends AbstractOffsetTimeAssert<SELF>>

    • Constructor Detail

      • AbstractOffsetTimeAssert

        protected AbstractOffsetTimeAssert​(OffsetTime actual,
                                           Class<?> selfType)
        Parameters:
        selfType - the "self type"
        actual - the actual value to verify
    • Method Detail

      • isBefore

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

        Example :

         assertThat(parse("12:00:00Z")).isBefore(parse("13:00:00Z"));
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not strictly before the given one.
      • isBeforeOrEqualTo

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

        Example :

         assertThat(parse("12:00:00Z")).isBeforeOrEqualTo(parse("12:00:00Z"))
                                       .isBeforeOrEqualTo(parse("12:00:01Z"));
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not before or equals to the given one.
      • isAfterOrEqualTo

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

        Example :

         assertThat(parse("13:00:00Z")).isAfterOrEqualTo(parse("13:00:00Z"))
                                       .isAfterOrEqualTo(parse("12:00:00Z"));
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not after or equals to the given one.
      • isAfter

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

        Example :

         assertThat(parse("13:00:00Z")).isAfter(parse("12:00:00Z"));
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not strictly after the given one.
      • convertToOffsetTimeArray

        private static Object[] convertToOffsetTimeArray​(String... offsetTimesAsString)
      • checkIsNotNullAndNotEmpty

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

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

        public SELF isEqualToIgnoringNanos​(OffsetTime other)
        Verifies that actual and given OffsetTime have same hour, minute and second fields (nanosecond fields are ignored in comparison).

        Assertion can fail with OffsetTimes in same chronological nanosecond time window, e.g :

        23:00:01.000000000+01:00 and 23:00:00.999999999+01:00.

        Assertion fails as second fields differ even if time difference is only 1ns.

        Code example :

         // successful assertions
         OffsetTime OffsetTime1 = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
         OffsetTime OffsetTime2 = OffsetTime.of(12, 0, 1, 456, ZoneOffset.UTC);
         assertThat(OffsetTime1).isEqualToIgnoringNanos(OffsetTime2);
        
         // failing assertions (even if time difference is only 1ns)
         OffsetTime OffsetTimeA = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
         OffsetTime OffsetTimeB = OffsetTime.of(12, 0, 0, 999999999, ZoneOffset.UTC);
         assertThat(OffsetTimeA).isEqualToIgnoringNanos(OffsetTimeB);
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not equal with nanoseconds ignored.
      • isEqualToIgnoringSeconds

        public SELF isEqualToIgnoringSeconds​(OffsetTime other)
        Verifies that actual and given OffsetTime have same hour and minute fields (second and nanosecond fields are ignored in comparison).

        Assertion can fail with OffsetTimes in same chronological second time window, e.g :

        23:01:00.000+01:00 and 23:00:59.000+01:00.

        Assertion fails as minute fields differ even if time difference is only 1s.

        Code example :

         // successful assertions
         OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
         OffsetTime OffsetTime2 = OffsetTime.of(23, 50, 10, 456, ZoneOffset.UTC);
         assertThat(OffsetTime1).isEqualToIgnoringSeconds(OffsetTime2);
        
         // failing assertions (even if time difference is only 1ms)
         OffsetTime OffsetTimeA = OffsetTime.of(23, 50, 00, 000, ZoneOffset.UTC);
         OffsetTime OffsetTimeB = OffsetTime.of(23, 49, 59, 999, ZoneOffset.UTC);
         assertThat(OffsetTimeA).isEqualToIgnoringSeconds(OffsetTimeB);
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not equal with second and nanosecond fields ignored.
      • isEqualToIgnoringTimezone

        public SELF isEqualToIgnoringTimezone​(OffsetTime other)
        Verifies that actual and given OffsetTime have same hour, minute, second and nanosecond fields).

        Code examples :

         // successful assertions
         OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
         OffsetTime offsetTime2 = OffsetTime.of(12, 0, 0, 0, ZoneOffset.MAX);
         assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2);
        
         // failing assertions (even if time difference is only 1ms)
         OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
         OffsetTime offsetTime2 = OffsetTime.of(12, 1, 0, 0, ZoneOffset.UTC);
         assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2); 
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not equal with timezone ignored.
      • hasSameHourAs

        public SELF hasSameHourAs​(OffsetTime other)
        Verifies that actual and given OffsetTime have same hour fields (minute, second and nanosecond fields are ignored in comparison).

        Assertion can fail with OffsetTimes in same chronological second time window, e.g :

        01:00:00.000+01:00 and 00:59:59.000+01:00.

        Time difference is only 1s but hour fields differ.

        Code example :

         // successful assertions
         OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
         OffsetTime OffsetTime2 = OffsetTime.of(23, 00, 2, 7, ZoneOffset.UTC);
         assertThat(OffsetTime1).hasSameHourAs(OffsetTime2);
        
         // failing assertions (even if time difference is only 1ms)
         OffsetTime OffsetTimeA = OffsetTime.of(01, 00, 00, 000, ZoneOffset.UTC);
         OffsetTime OffsetTimeB = OffsetTime.of(00, 59, 59, 999, ZoneOffset.UTC);
         assertThat(OffsetTimeA).hasSameHourAs(OffsetTimeB); 
        Parameters:
        other - the given OffsetTime.
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual OffsetTime is null.
        IllegalArgumentException - if other OffsetTime is null.
        AssertionError - if the actual OffsetTime is not equal ignoring minute, second and nanosecond fields.
      • isBetween

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

        Example:

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

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

        Example:

         OffsetTime oneAm = OffsetTime.parse("01:00:00+02:00");
        
         // assertions succeed:
         assertThat(oneAm).isBetween("00:59:59+02:00", "01:00:01+02:00")
                          .isBetween("01:00:00+02:00", "01:00:01+02:00")
                          .isBetween("00:59:59+02:00", "01:00:00+02:00")
                          .isBetween("01:00:00+02:00", "01:00:00+02:00")
        
         // assertion fails:
         assertThat(oneAm).isBetween("01:00:01+02:00", "02:00:01+02:00");
        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 OffsetTime.
        AssertionError - if the actual value is not in [start, end] period.
        Since:
        3.7.1
      • isStrictlyBetween

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

        Example:

         OffsetTime offsetTime = OffsetTime.now();
        
         // assertion succeeds:
         assertThat(offsetTime).isStrictlyBetween(offsetTime.minusSeconds(1), offsetTime.plusSeconds(1));
        
         // assertions fail:
         assertThat(offsetTime).isStrictlyBetween(offsetTime.minusSeconds(10), offsetTime.minusSeconds(1));
         assertThat(offsetTime).isStrictlyBetween(offsetTime.plusSeconds(1), offsetTime.plusSeconds(10));
         assertThat(offsetTime).isStrictlyBetween(offsetTime, offsetTime.plusSeconds(1));
         assertThat(offsetTime).isStrictlyBetween(offsetTime.minusSeconds(1), offsetTime);
        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(OffsetTime, OffsetTime) but here you pass OffsetTime String representations which must follow ISO OffsetTime format to allow calling OffsetTime.parse(CharSequence) method.

        Example:

         OffsetTime oneAm = OffsetTime.parse("01:00:00+02:00");
        
         // assertion succeeds:
         assertThat(oneAm).isStrictlyBetween("00:59:59+02:00", "01:00:01+02:00");
        
         // assertions fail:
         assertThat(oneAm).isStrictlyBetween("02:00:00+02:00", "03:00:00+02:00");
         assertThat(oneAm).isStrictlyBetween("00:59:59+02:00", "01:00:00+02:00");
         assertThat(oneAm).isStrictlyBetween("01:00:00+02:00", "01:00:01+02:00");
        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 OffsetTime.
        AssertionError - if the actual value is not in ]start, end[ period.
        Since:
        3.7.1
      • areEqualIgnoringNanos

        private static boolean areEqualIgnoringNanos​(OffsetTime actual,
                                                     OffsetTime other)
        Returns true if both OffsetTime are in the same hour, minute and second, false otherwise.
        Parameters:
        actual - the actual OffsetTime. expected not be null
        other - the other OffsetTime. expected not be null
        Returns:
        true if both OffsetTime are in the same year, month and day of month, hour, minute and second, false otherwise.
      • areEqualIgnoringSeconds

        private static boolean areEqualIgnoringSeconds​(OffsetTime actual,
                                                       OffsetTime other)
        Returns true if both OffsetTime are in the same hour and minute, false otherwise.
        Parameters:
        actual - the actual OffsetTime. expected not be null
        other - the other OffsetTime. expected not be null
        Returns:
        true if both OffsetTime are in the same hour and minute, false otherwise.
      • areEqualIgnoringTimezone

        private static boolean areEqualIgnoringTimezone​(OffsetTime actual,
                                                        OffsetTime other)
        Returns true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
        Parameters:
        actual - the actual OffsetTime. expected not be null
        other - the other OffsetTime. expected not be null
        Returns:
        true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
      • haveSameHourField

        private static boolean haveSameHourField​(OffsetTime actual,
                                                 OffsetTime other)