Closed
Description
Overview
Given a @MethodSource
factory method that accepts an array -- for example, Stream<Arguments> factory(int[] quantities)
:
- When using the fully qualified method name (FQMN), a user can supply either the binary or source (canonical) name for the array type.
@MethodSource("example.MethodSourceTests#factory([I)")
✅@MethodSource("example.MethodSourceTests#factory(int[])")
✅
- When using the local qualified method name (LQMN), a user should be able to supply either the binary or source (canonical) name for the array type; however, currently only the binary name is supported.
@MethodSource("factory([I)")
✅@MethodSource("factory(int[])")
❌
Examples
Given the following extension:
class IntegerArrayResolver implements ParameterResolver {
@Override
public boolean supportsParameter(ParameterContext pc, ExtensionContext ec) {
return pc.getParameter().getType() == int[].class;
}
@Override
public Object resolveParameter(ParameterContext pc, ExtensionContext ec) {
return new int[] { 2, 3 };
}
}
And given the following test class:
@ExtendWith(IntegerArrayResolver.class)
class MethodSourceTests {
@ParameterizedTest
// @MethodSource("example.MethodSourceTests#factory([I)")
// @MethodSource("example.MethodSourceTests#factory(int[])")
// @MethodSource("factory([I)")
@MethodSource("factory(int[])")
void test(String argument) {
assertTrue(argument.startsWith("2"));
}
static Stream<Arguments> factory(int quantities) {
return Stream.of(arguments(quantities + " apples"), arguments(quantities + " lemons"));
}
static Stream<Arguments> factory(int[] quantities) {
return Stream.of(arguments(quantities[0] + " apples"), arguments(quantities[0] + " lemons"));
}
}
All @MethodSource
variants that are commented out above work.
When running the test "as is", we get the following error.
org.junit.platform.commons.PreconditionViolationException: 2 factory methods named [factory(int[])] were found in class [example.MethodSourceTests]: [static java.util.stream.Stream example.MethodSourceTests.factory(int), static java.util.stream.Stream example.MethodSourceTests.factory(int[])]
Related Issues
- Parameters are not validated in local
@MethodSource
factory method #3130 - Local qualified
@MethodSource
factory method name treated differently than FQMN #3266
Deliverables
- Ensure that canonical array names are supported in the syntax for local qualified method names in
@MethodSource
.