Posted on Jun 22, 2010 by
Massive Monkey
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();
}
Comment #1
Posted on Jun 22, 2010 by Massive MonkeyThis issue was closed by revision r2022.
Comment #2
Posted on Jul 3, 2011 by Massive Monkey(No comment was entered for this change.)
Comment #3
Posted on Nov 2, 2011 by Happy HorseIssue 278 has been merged into this issue.
Status: Fixed
Labels:
Type-Defect
Priority-Low
Milestone-Release1.9-rc1