ssacher-tgm / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

polimorphic call not dispatched correctly #200

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Edge case around generics + inheritance. Below code did not work correctly due 
to polimorphic call not dispatched to correct method.

    protected interface MyIterable<T> extends Iterable<T> {
        public MyIterator<T> iterator();
    }

    protected interface MyIterator<T> extends Iterator<T> {
        // adds nothing here
    }

    MyIterator<String> myIterator = Mockito.mock(MyIterator.class);
    MyIterable<String> iterable = Mockito.mock(MyIterable.class);

    @Test
    public void shouldStubbingWork() {
        Mockito.when(iterable.iterator()).thenReturn(myIterator);
        Assert.assertNotNull(((Iterable) iterable).iterator());
        Assert.assertNotNull(iterable.iterator());
    }

    @Test
    public void shouldVerificationWorks() {
        iterable.iterator();

        verify(iterable).iterator();
        verify((Iterable) iterable).iterator();
    }

Original issue reported on code.google.com by szcze...@gmail.com on 22 Jun 2010 at 5:23

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r2022.

Original comment by szcze...@gmail.com on 22 Jun 2010 at 5:32

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 3 Jul 2011 at 12:43

GoogleCodeExporter commented 8 years ago
Issue 278 has been merged into this issue.

Original comment by brice.du...@gmail.com on 2 Nov 2011 at 9:34