Generic Types
AutoParams is capable of generating objects of generic types, adhering to its constructor selection policy. When dealing with generic types, AutoParams employs a public constructor with arbitrary arguments for object creation. If multiple public constructors are available, the framework opts for the one with the fewest parameters.
- Java
- Kotlin
@AllArgsConstructor
@Getter
public class GenericObject<T1, T2> {
private final T1 value1;
private final T2 value2;
}
class GenericObject<T1, T2>(
val value1: T1,
val value2: T2
)
- Java
- Kotlin
@ParameterizedTest
@AutoSource
void testMethod(
GenericObject<String, ComplexObject> arg1,
GenericObject<UUID, GenericObject<String, ComplexObject>> arg2) {
}
@ParameterizedTest
@AutoSource
fun testMethod(
arg1: GenericObject<String, ComplexObject>,
arg2: GenericObject<UUID, GenericObject<String, ComplexObject>>) {
}