Class ComparableSubject<T extends Comparable<?>>

java.lang.Object
com.google.common.truth.Subject
com.google.common.truth.ComparableSubject<T>
Type Parameters:
T - the type of the object being tested by this ComparableSubject
Direct Known Subclasses:
BigDecimalSubject, DoubleSubject, FloatSubject, IntegerSubject, LongSubject, StringSubject

public abstract class ComparableSubject<T extends Comparable<?>> extends Subject
A subject for Comparable values.
Author:
Kurt Alfred Kluever
  • Constructor Details

    • ComparableSubject

      protected ComparableSubject(FailureMetadata metadata, @Nullable T actual)
      Constructor for use by subclasses. If you want to create an instance of this class itself, call check(...).that(actual).
  • Method Details

    • isIn

      public final void isIn(@Nullable Range<T> range)
      Checks that the actual value is in range.
    • isNotIn

      public final void isNotIn(@Nullable Range<T> range)
      Checks that the actual value is not in range.
    • isEquivalentAccordingToCompareTo

      public void isEquivalentAccordingToCompareTo(@Nullable T expected)
      Checks that the actual value is equivalent to other according to Comparable.compareTo(T), (i.e., checks that a.comparesTo(b) == 0).

      Note: Do not use this method for checking object equality. Instead, use Subject.isEqualTo(Object).

    • isGreaterThan

      public final void isGreaterThan(@Nullable T other)
      Checks that the actual value is greater than other.

      To check that the actual value is greater than or equal to other, use isAtLeast(T).

    • isLessThan

      public final void isLessThan(@Nullable T other)
      Checks that the actual value is less than other.

      To check that the actual value is less than or equal to other, use isAtMost(T).

    • isAtMost

      public final void isAtMost(@Nullable T other)
      Checks that the actual value is less than or equal to other.

      To check that the actual value is strictly less than other, use isLessThan(T).

    • isAtLeast

      public final void isAtLeast(@Nullable T other)
      Checks that the actual value is greater than or equal to other.

      To check that the actual value is strictly greater than other, use isGreaterThan(T).