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 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 returns objectType().
        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 of covariantReturnType().
        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 of objectType() that have baseReturnType() 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.