108bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann/*
208bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann * Copyright (c) 2017 Mockito contributors
308bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann * This program is made available under the terms of the MIT License.
408bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann */
52637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpackage org.mockitousage.bugs;
62637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
708bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmannimport static org.junit.Assert.assertEquals;
808bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann
92637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.junit.Test;
102637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.Mockito;
112637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
122637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin// see #508
132637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpublic class DiamondInheritanceIsConfusingMockitoTest {
142637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
152637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    @Test
162637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public void should_work() {
172637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        Sub mock = Mockito.mock(Sub.class);
182637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        // The following line results in
192637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        // org.mockito.exceptions.misusing.MissingMethodInvocationException:
202637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        // when() requires an argument which has to be 'a method call on a mock'.
212637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        // Presumably confused by the interface/superclass signatures.
222637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        Mockito.when(mock.getFoo()).thenReturn("Hello");
232637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
2408bd32ce48b12ae751dd5c4829ff09a6fb9894f0Philip P. Moltmann        assertEquals("Hello", mock.getFoo());
252637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
262637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
272637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public class Super<T> {
282637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        private T value;
292637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
302637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public Super(T value) {
312637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            this.value = value;
322637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
332637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
342637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public T getFoo() { return value; }
352637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
362637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
372637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public class Sub
382637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            extends Super<String>
392637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            implements iInterface {
402637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
412637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        public Sub(String s) {
422637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin            super(s);
432637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        }
442637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
452637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin
462637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    public interface iInterface {
472637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin        String getFoo();
482637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin    }
492637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin}
50