1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockitousage.puzzlers; 6 7 import org.junit.Test; 8 import org.mockito.exceptions.verification.WantedButNotInvoked; 9 import org.mockitoutil.TestBase; 10 11 import static org.junit.Assert.fail; 12 import static org.mockito.Mockito.mock; 13 import static org.mockito.Mockito.verify; 14 15 public class OverloadingPuzzleTest extends TestBase { 16 17 private Super mock; 18 setMockWithDowncast(Super mock)19 private void setMockWithDowncast(Super mock) { 20 this.mock = mock; 21 } 22 23 private interface Super { say(Object message)24 void say(Object message); 25 } 26 27 private interface Sub extends Super { say(String message)28 void say(String message); 29 } 30 say(Object message)31 private void say(Object message) { 32 mock.say(message); 33 } 34 35 @Test shouldUseArgumentTypeWhenOverloadingPuzzleDetected()36 public void shouldUseArgumentTypeWhenOverloadingPuzzleDetected() throws Exception { 37 Sub sub = mock(Sub.class); 38 setMockWithDowncast(sub); 39 say("Hello"); 40 try { 41 verify(sub).say("Hello"); 42 fail(); 43 } catch (WantedButNotInvoked e) {} 44 } 45 } 46