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