Skip to content

Third-party ParameterResolvers may potentially conflict with ParameterizedTestParameterResolver #1184

@smoyer64

Description

@smoyer64

Overview

In the following code snippet, the Weld CDI system provides a ParameterResolver for the third parameter in the parametersTakePriorityOverInjection() method. Since the@TestTemplate "knows" that it's producing parameters for the first two parameters via its ArgumentSource, it shouldn't call either the supportsParameter() or resolvesParameter() methods of Weld's ParameterResolver. Other registered ParameterResolvers should only be called for parameters with indexes greater than one.

@ExtendWith(WeldJunit5Extension.class)
public class ParameterizedTestCompatibilityTest {

	static final String SENTENCE = " is a greek letter.";

	@ParameterizedTest
	@CsvSource({
			"Alpha, 0",
			"Beta, 1",
			"Gamma, 2"
	})
	void parametersTakePriorityOverInjection(String letter, int ordinal, String sentence) {
		assertTrue(letter.length() >= 4);
		assertTrue(ordinal >= 0 && ordinal <= 2);
		assertEquals(SENTENCE, sentence);
	}

	@Produces
	@ApplicationScoped
	String produceSentence() {
		return " is a greek letter.";
	}

}

When run, this code currently throws a ParameterResolutionException with the message:

Discovered multiple competing ParameterResolvers for parameter [java.lang.String arg0] in executable [void org.jboss.weld.junit5.compatibility.ParameterizedTestCompatibilityTest.parametersTakePriorityOverInjection(java.lang.String,int,java.lang.String)]: org.jboss.weld.junit5.WeldJunit5Extension, org.junit.jupiter.params.ParameterizedTestParameterResolver

This issue is somewhat related to #935 but occurs when additional parameters are correctly placed after those injected by the TestTemplate.

Versions

  • junit-jupiter-api: 5.0.1, 5.0.2, 5.1 M1
  • junit-jupiter-params: 5.0.1, 5.0.2, 5.1 M1

Related Issues

Deliverables

  • Parameterized tests should ignore other registered parameter resolvers for parameters that will be satisfied by an ArgumentSource.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions