-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overloaded method accepting arguments clashes with intended @MethodSource
factory method
#3080
Comments
@MethodSource
factory method@MethodSource
factory method
I believe I mentioned this elsewhere, but I'll restate it here... The current workaround is to use the fully qualified method name to disambiguate between overloaded methods. However, that is extremely verbose for a locally declared factory method. For example, the failing test can be fixed with one of the following. @MethodSource("example.MethodSourceFactoryTests$FailingTests#data") or @MethodSource("example.MethodSourceFactoryTests$FailingTests#data()") To improve the developer experience, we could introduce a simplified syntax for selecting a local factory method (local to the current type hierarchy -- in other words not in an external class). The following are examples of how this could look (omitting the fully qualified class name). @MethodSource("data()") or @MethodSource("#data()") In summary, the user originally had this: @MethodSource("data") ... which leads to ambiguous factory method selection. And I'm proposing that the user can switch to this for explicit local factory method selection. @MethodSource("data()") // or @MethodSource("#data()") @junit-team/junit-lambda, thoughts? |
SGTM 👍 |
I've intentionally labeled this issue as both a
|
Team decision: Let's go with |
This commit fixes a bug regarding whitespace in parameter lists for local factory methods specified via `@MethodSource`. Specifically, whitespace is now supported. For example, @MethodSource("data(int, java.lang.String)") is now supported (note the space after the comma). As a side note, whitespace in parameter lists was already supported for a fully qualified method name. See #3080, #3101
This commit fixes a bug regarding whitespace in parameter lists for local factory methods specified via `@MethodSource`. Specifically, whitespace is now supported. For example, @MethodSource("data(int, java.lang.String)") is now supported (note the space after the comma). As a side note, whitespace in parameter lists was already supported for a fully qualified method name. See #3080, #3101
There was a change of behaviour in 5.9.0 where methods with arguments became considered candidate factory methods causing it to throw exceptions when it was ambiguous which method was targeted. junit-team/junit5#3080 junit-team/junit5@825ea38 https://junit.org/junit5/docs/current/release-notes/index.html#bug-fixes-2
There was a change of behaviour in 5.9.0 where methods with arguments became considered candidate factory methods causing it to throw exceptions when it was ambiguous which method was targeted. junit-team/junit5#3080 junit-team/junit5@825ea38 https://junit.org/junit5/docs/current/release-notes/index.html#bug-fixes-2
Overview
As mentioned in #2191 (comment), prior to Jupiter 5.9 if an overloaded method that accepts arguments also met the criteria for a factory method (based on the return type), that method would not have been considered a factory method.
However, as of Jupiter 5.9 (including 5.9.1) such an overloaded method will be considered a candidate factory method. Consequently, if that method is an overload for the intended
@MethodSource
factory method an exception will be thrown stating that multiple competing factory methods were discovered.Example
WorkingTests
succeeds.FailingTests
fails because it extendsBase
.Related Issues
ReflectionUtils.findMethods()
returns duplicate methods, breaking certain use cases #2993@MethodSource
factory method resolution #3001Deliverables
The text was updated successfully, but these errors were encountered: