jmockit/jmockit1

mockit.internal.expectations.invocation.ExpectedInvocation#isMatchingGenericMethod don't match method name as isMatchingMethod did

Nick-The-Uncharted opened this issue · 2 comments

Please provide the following information:

  • Version of JMockit that was used:
    1.48
  • Description of the problem or enhancement request:

When instanced called is a subclass of mocking instance, and called method has a generic signature, mockit.internal.expectations.invocation.ExpectedInvocation#isMatchingGenericMethod will only match signature (return type and params type).

  • Check the following:
  • If a defect or unexpected result, JMockit project members should be able to reproduce it.
    For that, include an example test (perhaps accompanied by a Maven/Gradle build script) which
    can be executed without changes and reproduces the failure.

  • If an enhancement or new feature request, it should be justified by an example test
    demonstrating the validity and usefulness of the desired enhancement or new feature.

  • The issue does not fall outside the scope of the project (for example, attempting to use
    JMockit APIs from Groovy or Scala code, or with an Android runtime).

  • The JDK where the problem occurs is a final release, not a development build.

Snippet to reproduce it:

public class GenericTest {
    public static class ClassWithGenericMethod {
        public List<String> m() {
            return null;
        }

        public List<Integer> m2() {
            return null;
        }
    }

    @Test
    public void test(@Capturing ClassWithGenericMethod classWithGenericMethod) {
        new Expectations() {
            {
                classWithGenericMethod.m();
                result = Collections.singletonList("hello");
            }
        };
        System.out.println(new ClassWithGenericMethod(){}.m2()); // prints "[hello]"
    }
}

I think this is the same issue as #708 . You can try to use PR #712 and check if it helps you.

@Saljack Thank you, this fixed my problem. I am suprised this mr still haven't been merged....