Class Expectable<T>

java.lang.Object
de.oliver.plugintests.Expectable<T>
Type Parameters:
T - the type of the value to be asserted.

public class Expectable<T> extends Object
A generic class for making assertions on the expected values.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Expectable<T>
    expect(T t)
    Creates a new instance of Expectable for the given value.
    void
    toBe(T expected)
    Asserts that the actual value is equal to the expected value.
    void
    Ensures that the actual value is not null.
    void
    toBeGreaterThan(T expected)
    Asserts that the actual value is greater than the expected value.
    void
    toBeInstanceOf(Class<?> expected)
    Asserts that the actual value is an instance of the expected class.
    void
    toBeLessThan(T expected)
    Asserts that the actual value is less than the expected value.
    void
    Asserts that the value of the field 't' is null.
    void
    toContain(Object expected)
    Asserts that the given expected value is contained within the actual value.
    void
    toEqual(T expected)
    Asserts that the actual value is equal to the expected value using the equals method.
    void
    toHaveLength(int expected)
    Asserts that the actual value has the expected length.
    <E extends Throwable>
    E
    toThrow(Class<E> expected)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • expect

      public static <T> Expectable<T> expect(T t)
      Creates a new instance of Expectable for the given value.
      Type Parameters:
      T - the type of the value being tested
      Parameters:
      t - the actual value to create an expectation for
      Returns:
      a new Expectable instance for the given value
    • toBeDefined

      public void toBeDefined()
      Ensures that the actual value is not null.

      Throws an AssertionError if the value of the field 't' is null, indicating that the actual value is expected to be non-null.

      Throws:
      AssertionError - if the value of the field 't' is null
    • toBeNull

      public void toBeNull()
      Asserts that the value of the field 't' is null.

      Throws an AssertionError if the value of 't' is not null, indicating the expectation that the value should be null.

      Throws:
      AssertionError - if the value of 't' is not null
    • toBe

      public void toBe(T expected)
      Asserts that the actual value is equal to the expected value.
      Parameters:
      expected - the value that the actual value is expected to be equal to
      Throws:
      AssertionError - if the actual value is not equal to the expected value
    • toEqual

      public void toEqual(T expected)
      Asserts that the actual value is equal to the expected value using the equals method.
      Parameters:
      expected - the value that the actual value is expected to be equal to
      Throws:
      AssertionError - if the actual value is not equal to the expected value
    • toBeGreaterThan

      public void toBeGreaterThan(T expected)
      Asserts that the actual value is greater than the expected value.
      Parameters:
      expected - the value that the actual value is expected to be greater than
      Throws:
      AssertionError - if the actual value is not greater than the expected value, or if the type of the actual value is not one of Integer, Long, Float, or Double
    • toBeLessThan

      public void toBeLessThan(T expected)
      Asserts that the actual value is less than the expected value.
      Parameters:
      expected - the value that the actual value is expected to be less than
      Throws:
      AssertionError - if the actual value is not less than the expected value, or if the type of the actual value is not one of Integer, Long, Float, or Double
    • toBeInstanceOf

      public void toBeInstanceOf(Class<?> expected)
      Asserts that the actual value is an instance of the expected class. This method checks whether the value held in the field 't' is an instance of the provided Class.
      Parameters:
      expected - the Class object that the actual value is expected to be an instance of
      Throws:
      AssertionError - if the actual value is not an instance of the expected class
    • toContain

      public void toContain(Object expected)
      Asserts that the given expected value is contained within the actual value.

      This method checks if the expected value is present in a String, Iterable, or Array. If the actual value is a String, it uses the contains method to check if the expected value is a substring. If the actual value is an Iterable, it checks if the expected value is an element. If the actual value is an Array, it checks if the expected value is present in the array.

      Parameters:
      expected - the value that is expected to be contained within the actual value
      Throws:
      AssertionError - if the expected value is not contained within the actual value
    • toHaveLength

      public void toHaveLength(int expected)
      Asserts that the actual value has the expected length. This method checks if the actual value is a String, Iterable, or Array, and compares their length or size to the given expected length.
      Parameters:
      expected - the expected length of the actual value
      Throws:
      AssertionError - if the actual value does not have the expected length, or if the actual value is not of type String, Iterable, or Array
    • toThrow

      public <E extends Throwable> E toThrow(Class<E> expected)