• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.mockitousage.bugs;
2 
3 import org.junit.Assert;
4 import org.junit.Test;
5 import org.mockito.Mockito;
6 
7 // see #508
8 public class DiamondInheritanceIsConfusingMockitoTest {
9 
10     @Test
should_work()11     public void should_work() {
12         Sub mock = Mockito.mock(Sub.class);
13         // The following line results in
14         // org.mockito.exceptions.misusing.MissingMethodInvocationException:
15         // when() requires an argument which has to be 'a method call on a mock'.
16         // Presumably confused by the interface/superclass signatures.
17         Mockito.when(mock.getFoo()).thenReturn("Hello");
18 
19         Assert.assertEquals("Hello", mock.getFoo());
20     }
21 
22     public class Super<T> {
23         private T value;
24 
Super(T value)25         public Super(T value) {
26             this.value = value;
27         }
28 
getFoo()29         public T getFoo() { return value; }
30     }
31 
32     public class Sub
33             extends Super<String>
34             implements iInterface {
35 
Sub(String s)36         public Sub(String s) {
37             super(s);
38         }
39     }
40 
41     public interface iInterface {
getFoo()42         String getFoo();
43     }
44 }
45