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.assertj.core.api.Assertions.assertThat;
8 import static org.mockito.Mockito.mock;
9 import static org.mockito.Mockito.when;
10 
11 import org.junit.Test;
12 
13 public class ConfusedSignatureTest {
14 
15     @Test
should_mock_method_which_has_generic_return_type_in_superclass_and_concrete_one_in_interface()16     public void should_mock_method_which_has_generic_return_type_in_superclass_and_concrete_one_in_interface() {
17         Sub mock = mock(Sub.class);
18         // The following line resulted 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         when(mock.getFoo()).thenReturn("Hello");
23 
24         assertThat(mock.getFoo()).isEqualTo("Hello");
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