Generics doesn't work properly in chained method calls #213

Closed
ChristophLu opened this Issue Oct 8, 2015 · 1 comment

Projects

None yet

3 participants

@ChristophLu

With JMockit 1.19 I have the following test code:

public class MockTest {
    public interface Baz {
    }

    public interface Bar {

        public Baz getBaz(String name);
    }

    public interface Foo {

        public <DataT> Bar getBar(DataT model); // this does not work: "baz" is null
        // public Bar getBar(String model); // this works!
    }

    @Test
    public void test_cascading_class(@Mocked Foo foo) {
        assertNotNull(foo);
        final Bar bar = foo.getBar("blah");
        assertNotNull(bar);
        final Baz baz = bar.getBaz("foo"); // "baz" is null
        assertNotNull(baz);
    }
}

The third assertion is null if using getBar() with generics. If I use the method without generics all works fine.

@SimFirehawk

I can confirm it. The problem should still be existing in version 1.20. It is related to MockedTypeCascade in method getGenericReturnType specific in line 105.
The return value of getInternalReturnTypeCodeAndName(..) is used, but it should return only the name without the type code.

@rliesenfeld rliesenfeld added the bug label Oct 8, 2015
@rliesenfeld rliesenfeld self-assigned this Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment