Class Offset<T extends Number>

  • Type Parameters:
    T - the type of the offset value.

    public final class Offset<T extends Number>
    extends Object
    A positive offset.
    Author:
    Alex Ruiz, Yvonne Wang
    • Field Detail

      • value

        public final T extends Number value
      • strict

        public final boolean strict
        When |actual-expected|=offset and strict is true the assertThat(actual).isCloseTo(expected, offset); assertion will fail.
    • Constructor Detail

      • Offset

        private Offset​(T value,
                       boolean strict)
    • Method Detail

      • offset

        public static <T extends NumberOffset<T> offset​(T value)
        Creates a new Offset that let isCloseTo assertions pass when |actual-expected| <= offset value.

        Example:

         // assertions succeed
         assertThat(8.1).isCloseTo(8.0, offset(0.2));
         assertThat(8.1).isCloseTo(8.0, offset(0.1));
        
         // assertion fails
         assertThat(8.1).isCloseTo(8.0, offset(0.01));
        Type Parameters:
        T - the type of value of the Offset.
        Parameters:
        value - the value of the offset.
        Returns:
        the created Offset.
        Throws:
        NullPointerException - if the given value is null.
        IllegalArgumentException - if the given value is negative.
      • strictOffset

        public static <T extends NumberOffset<T> strictOffset​(T value)
        Creates a new strict Offset that let isCloseTo assertion pass when |actual-expected| < offset value.

        Examples:

         // assertion succeeds
         assertThat(8.1).isCloseTo(8.0, offset(0.2));
        
         // assertions fail
         assertThat(8.1).isCloseTo(8.0, offset(0.1));
         assertThat(8.1).isCloseTo(8.0, offset(0.01));
        Type Parameters:
        T - the type of value of the Offset.
        Parameters:
        value - the value of the offset.
        Returns:
        the created Offset.
        Throws:
        NullPointerException - if the given value is null.
        IllegalArgumentException - if the given value is negative.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object