Class Offset<T extends java.lang.Number>

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

    public class Offset<T extends java.lang.Number>
    extends java.lang.Object
    A positive offset.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean strict
      When |actual-expected|=offset and strict is true the assertThat(actual).isCloseTo(expected, offset); assertion will fail.
      T value  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Offset​(T value, boolean strict)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      int hashCode()  
      static <T extends java.lang.Number>
      Offset<T>
      offset​(T value)
      Creates a new Offset that let isCloseTo assertions pass when |actual-expected| <= offset value.
      static <T extends java.lang.Number>
      Offset<T>
      strictOffset​(T value)
      Creates a new strict Offset that let isCloseTo assertion pass when |actual-expected| < offset value.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • value

        public final T extends java.lang.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 java.lang.Number> Offset<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:
        java.lang.NullPointerException - if the given value is null.
        java.lang.IllegalArgumentException - if the given value is negative.
      • strictOffset

        public static <T extends java.lang.Number> Offset<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:
        java.lang.NullPointerException - if the given value is null.
        java.lang.IllegalArgumentException - if the given value is negative.
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object