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 class
DelegateTests.DelegateMethod<T>
A representation of a method that, when in invoked on an instance, delegates to another instance of the same type.static class
DelegateTests.Parameter
A 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.Parameter
parameter(boolean value)
Creates a newboolean
method parameter.default DelegateTests.Parameter
parameter(byte value)
Creates a newbyte
method parameter.default DelegateTests.Parameter
parameter(char value)
Creates a newchar
method parameter.default DelegateTests.Parameter
parameter(double value)
Creates a newdouble
method parameter.default DelegateTests.Parameter
parameter(float value)
Creates a newfloat
method parameter.default DelegateTests.Parameter
parameter(int value)
Creates a newint
method parameter.default DelegateTests.Parameter
parameter(long value)
Creates a newlong
method parameter.default DelegateTests.Parameter
parameter(short value)
Creates a newshort
method parameter.default DelegateTests.Parameter
parameter(Class<?> type)
Creates a new method parameter.default <U> DelegateTests.Parameter
parameter(Class<U> type, U value)
Creates a new method parameter.default <U> DelegateTests.Parameter
parameter(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.T
wrap(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;
0
forint
,false
forboolean
,null
for 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)
wheredefaultValue
is the default value for the given type:0
forint
,false
forboolean
,null
for 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 newboolean
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(char value)
Creates a newchar
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(byte value)
Creates a newbyte
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(short value)
Creates a newshort
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(int value)
Creates a newint
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(long value)
Creates a newlong
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(float value)
Creates a newfloat
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
parameter
default DelegateTests.Parameter parameter(double value)
Creates a newdouble
method parameter.- Parameters:
value
- The value for the parameter.- Returns:
- The created method parameter.
-
-