Skip to content

Syntax for local @MethodSource factory method does not support canonical array names #3131

Closed
@sbrannen

Description

@sbrannen

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

Deliverables

  • Ensure that canonical array names are supported in the syntax for local qualified method names in @MethodSource.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions