Home | History | Annotate | Download | only in bugs
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockitousage.bugs;
      7 
      8 import org.junit.Test;
      9 import org.mockito.Mock;
     10 import org.mockito.Mockito;
     11 import org.mockitoutil.TestBase;
     12 
     13 import java.io.Serializable;
     14 
     15 import static junit.framework.TestCase.assertTrue;
     16 import static org.mockito.Mockito.mock;
     17 import static org.mockito.Mockito.verify;
     18 
     19 //see issue 101
     20 public class BridgeMethodsHitAgainTest extends TestBase {
     21 
     22   public interface Factory {}
     23   public interface ExtendedFactory extends Factory {}
     24 
     25   public interface SomeInterface {
     26     Factory factory();
     27   }
     28 
     29   public interface SomeSubInterface extends SomeInterface {
     30     ExtendedFactory factory();
     31   }
     32 
     33   public interface Base<T extends Serializable> {
     34     int test(T value);
     35   }
     36 
     37   public interface Extended extends Base<String> {
     38     @Override
     39     int test(String value);
     40   }
     41 
     42   @Mock SomeSubInterface someSubInterface;
     43   @Mock ExtendedFactory extendedFactory;
     44 
     45   @Test
     46   public void basicCheck() {
     47     Mockito.when((someSubInterface).factory()).thenReturn(extendedFactory);
     48     SomeInterface si = someSubInterface;
     49     assertTrue(si.factory() != null);
     50   }
     51 
     52   @Test
     53   public void checkWithExtraCast() {
     54     Mockito.when(((SomeInterface) someSubInterface).factory()).thenReturn(extendedFactory);
     55     SomeInterface si = someSubInterface;
     56     assertTrue(si.factory() != null);
     57   }
     58 
     59     @Test
     60     public void testBridgeInvocationIsRecordedForInterceptedMethod() {
     61         Extended ext = mock(Extended.class);
     62         ext.test("123");
     63         verify(ext).test("123");
     64         ((Base<String>) ext).test("456");
     65         verify(ext).test("456");
     66     }
     67 }
     68