T
- The type of object to test.public interface DelegateTests<T>
Modifier and Type | Interface and 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.
|
Modifier and Type | Method and 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,
Class<?>... parameterTypes)
Returns a delegate method for a method.
|
default DelegateTests.DelegateMethod<T> |
method(String name,
DelegateTests.Parameter... parameters)
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 new
boolean method parameter. |
default DelegateTests.Parameter |
parameter(byte value)
Creates a new
byte method parameter. |
default DelegateTests.Parameter |
parameter(char value)
Creates a new
char 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 DelegateTests.Parameter |
parameter(double value)
Creates a new
double method parameter. |
default DelegateTests.Parameter |
parameter(float value)
Creates a new
float method parameter. |
default DelegateTests.Parameter |
parameter(int value)
Creates a new
int method parameter. |
default DelegateTests.Parameter |
parameter(long value)
Creates a new
long method parameter. |
default DelegateTests.Parameter |
parameter(short value)
Creates a new
short 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 by
methods() , test that the result of wrap(Object) delegates to its argument. |
T |
wrap(T delegate)
Creates the object to test.
|
Class<T> delegateType()
T wrap(T delegate)
delegate
- The delegate to test against.Stream<DelegateTests.DelegateMethod<T>> methods()
Note: the result should not include a delegate method for Object.equals(Object)
, Object.hashCode()
, private methods,
static methods or final methods.
@TestFactory @DisplayName(value="delegates") default Stream<DynamicTest> testDelegates()
methods()
, test that the result of wrap(Object)
delegates to its argument.default DelegateTests.DelegateMethod<T> method(String name)
name
- The name for the method.default DelegateTests.DelegateMethod<T> method(String name, Class<?>... parameterTypes)
The method will be invoked with default arguments; 0
for int
, false
for boolean
, 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.
Use method(String, Parameter...)
instead if the default arguments are not sufficient.
name
- The name for the method.parameterTypes
- The parameter types for the method.default DelegateTests.DelegateMethod<T> method(String name, DelegateTests.Parameter... parameters)
name
- The name for the method.parameters
- The parameters for the method.default <U> DelegateTests.Parameter parameter(U value)
parameter(value.getClass(), value)
.U
- The parameter type.value
- The value for the parameter.default DelegateTests.Parameter parameter(Class<?> type)
parameter(type, defaultValue)
where defaultValue
is the default value for the
given type: 0
for int
, false
for boolean
, null
for objects, etc.type
- The parameter type.default <U> DelegateTests.Parameter parameter(Class<U> type, U value)
U
- The parameter type.type
- The parameter type.value
- The value for the parameter.default DelegateTests.Parameter parameter(boolean value)
boolean
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(char value)
char
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(byte value)
byte
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(short value)
short
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(int value)
int
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(long value)
long
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(float value)
float
method parameter.value
- The value for the parameter.default DelegateTests.Parameter parameter(double value)
double
method parameter.value
- The value for the parameter.Copyright © 2020–2023. All rights reserved.