Interface CovariantReturnTests<T>
-
- Type Parameters:
T
- The type of object to test.
public interface CovariantReturnTests<T>
Base interface for testing that methods return a specific sub type of the overridden method of the super class. This can particularly be useful for testing that chainable method calls remain chainable in the sub class.- Author:
- Rob Spoor
- Since:
- 1.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Class<?>
baseReturnType()
Returns the base return type to test against.default Class<?>
covariantReturnType()
Returns the covariant return type to test for.default Stream<Method>
methods()
Returns a stream of methods to test.Class<T>
objectType()
Returns the type of object to test.default Stream<DynamicContainer>
testCovariantReturnTypes()
For each method returned bymethods()
, test that the method is overridden byobjectType()
and hascovariantReturnType()
as return type.
-
-
-
Method Detail
-
objectType
Class<T> objectType()
Returns the type of object to test.- Returns:
- The type of object to test.
-
covariantReturnType
default Class<?> covariantReturnType()
Returns the covariant return type to test for. This default implementation returnsobjectType()
.- Returns:
- The covariant return type to test for.
-
baseReturnType
default Class<?> baseReturnType()
Returns the base return type to test against. This default implementation returns the super class ofcovariantReturnType()
.- Returns:
- The base return type to test against.
-
methods
default Stream<Method> methods()
Returns a stream of methods to test. This default implementation returns all public methods of the super class ofobjectType()
that havebaseReturnType()
as return type. Note that this includes static methods; those can be excluded by adding additional filtering:@Override public Stream<Method> methods() { return CovariantReturnTests.super.methods() .filter(m -> !Modifier.isStatic(m.getModifiers())); }
- Returns:
- A stream of methods to test.
-
testCovariantReturnTypes
@TestFactory @DisplayName("covariant return types") default Stream<DynamicContainer> testCovariantReturnTypes()
For each method returned bymethods()
, test that the method is overridden byobjectType()
and hascovariantReturnType()
as return type.- Returns:
- A stream with the tests, one per method.
-
-