jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
465 stars 240 forks source link

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

Closed Nick-The-Uncharted closed 3 years ago

Nick-The-Uncharted commented 3 years ago

Please provide the following information:

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).

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]"
    }
}
Saljack commented 3 years ago

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

Nick-The-Uncharted commented 3 years ago

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