Package de.oliver.fancylib.tests
Class Expectable<T>
java.lang.Object
de.oliver.fancylib.tests.Expectable<T>
- Type Parameters:
T- the type of the value to be asserted.
A generic class for making assertions on the expected values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Expectable<T>expect(T t) Creates a new instance of Expectable for the given value.voidAsserts that the actual value is equal to the expected value.voidEnsures that the actual value is not null.voidtoBeGreaterThan(T expected) Asserts that the actual value is greater than the expected value.voidtoBeInstanceOf(Class<?> expected) Asserts that the actual value is an instance of the expected class.voidtoBeLessThan(T expected) Asserts that the actual value is less than the expected value.voidtoBeNull()Asserts that the value of the field 't' is null.voidAsserts that the given expected value is contained within the actual value.voidAsserts that the actual value is equal to the expected value using theequalsmethod.voidtoHaveLength(int expected) Asserts that the actual value has the expected length.
-
Method Details
-
expect
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
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
Asserts that the actual value is equal to the expected value using theequalsmethod.- 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
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
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
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
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
-