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