Interface DelegateTests<T>
-
- Type Parameters:
T- The type of object to test.
public interface DelegateTests<T>Base interface for testing that methods delegate to another object of the same type.- Author:
- Rob Spoor
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classDelegateTests.DelegateMethod<T>A representation of a method that, when in invoked on an instance, delegates to another instance of the same type.static classDelegateTests.ParameterA representation of a method parameter.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Class<T>delegateType()Returns the type to delegate to.default DelegateTests.DelegateMethod<T>method(String name)Returns a delegate method for a method without arguments.default DelegateTests.DelegateMethod<T>method(String name, DelegateTests.Parameter... parameters)Returns a delegate method for a method.default DelegateTests.DelegateMethod<T>method(String name, Class<?>... parameterTypes)Returns a delegate method for a method.Stream<DelegateTests.DelegateMethod<T>>methods()Returns the delegate methods to test.default DelegateTests.Parameterparameter(boolean value)Creates a newbooleanmethod parameter.default DelegateTests.Parameterparameter(byte value)Creates a newbytemethod parameter.default DelegateTests.Parameterparameter(char value)Creates a newcharmethod parameter.default DelegateTests.Parameterparameter(double value)Creates a newdoublemethod parameter.default DelegateTests.Parameterparameter(float value)Creates a newfloatmethod parameter.default DelegateTests.Parameterparameter(int value)Creates a newintmethod parameter.default DelegateTests.Parameterparameter(long value)Creates a newlongmethod parameter.default DelegateTests.Parameterparameter(short value)Creates a newshortmethod parameter.default DelegateTests.Parameterparameter(Class<?> type)Creates a new method parameter.default <U> DelegateTests.Parameterparameter(Class<U> type, U value)Creates a new method parameter.default <U> DelegateTests.Parameterparameter(U value)Creates a new method parameter.default Stream<DynamicTest>testDelegates()For each method returned by the object returned bymethods(), test that the result ofwrap(Object)delegates to its argument.Twrap(T delegate)Creates the object to test.
-
-
-
Method Detail
-
delegateType
Class<T> delegateType()
Returns the type to delegate to.- Returns:
- The type to delegate to.
-
wrap
T wrap(T delegate)
Creates the object to test.- Parameters:
delegate- The delegate to test against.- Returns:
- The created object.
-
methods
Stream<DelegateTests.DelegateMethod<T>> methods()
Returns the delegate methods to test.Note: the result should not include a delegate method for
Object.equals(Object),Object.hashCode(), private methods, static methods or final methods.- Returns:
- A stream with the delegate methods to test.
-
testDelegates
@TestFactory @DisplayName("delegates") default Stream<DynamicTest> testDelegates()
For each method returned by the object returned bymethods(), test that the result ofwrap(Object)delegates to its argument.- Returns:
- A stream with the tests, one per method.
-
method
default DelegateTests.DelegateMethod<T> method(String name)
Returns a delegate method for a method without arguments.- Parameters:
name- The name for the method.- Returns:
- A delegate method for the method with the given name and no arguments.
-
method
default DelegateTests.DelegateMethod<T> method(String name, Class<?>... parameterTypes)
Returns a delegate method for a method.The method will be invoked with default arguments;
0forint,falseforboolean,nullfor objects, etc. This may cause an error if the result of the method is invoked on an object that performs some input validation before delegating. Usemethod(String, Parameter...)instead if the default arguments are not sufficient.- Parameters:
name- The name for the method.parameterTypes- The parameter types for the method.- Returns:
- A delegate method for the method with the given name and parameter types.
-
method
default DelegateTests.DelegateMethod<T> method(String name, DelegateTests.Parameter... parameters)
Returns a delegate method for a method.- Parameters:
name- The name for the method.parameters- The parameters for the method.- Returns:
- A delegate method for the method with the given name and parameters.
-
parameter
default <U> DelegateTests.Parameter parameter(U value)
Creates a new method parameter. This is shorthand forparameter(value.getClass(), value).- Type Parameters:
U- The parameter type.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(Class<?> type)
Creates a new method parameter. This is shorthand forparameter(type, defaultValue)wheredefaultValueis the default value for the given type:0forint,falseforboolean,nullfor objects, etc.- Parameters:
type- The parameter type.- Returns:
- The created method parameter.
-
parameter
default <U> DelegateTests.Parameter parameter(Class<U> type, U value)
Creates a new method parameter.- Type Parameters:
U- The parameter type.- Parameters:
type- The parameter type.value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(boolean value)
Creates a newbooleanmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(char value)
Creates a newcharmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(byte value)
Creates a newbytemethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(short value)
Creates a newshortmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(int value)
Creates a newintmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(long value)
Creates a newlongmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(float value)
Creates a newfloatmethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(double value)
Creates a newdoublemethod parameter.- Parameters:
value- The value for the parameter.- Returns:
- The created method parameter.
-
-