PasqualeJ / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Mockito spy is unable to verify protected method call from within an anonymous class #508

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Here's my scenario:

public interface Invoker
{
    void invoke();
}

public class Foo
{
   private Invoker m_invoker;

   public Foo()
   {
       m_invoker = new Invoker(){
           bar();
       };
   }

   protected void bar() 
   {
       System.out.println("bar is indeed invoked! but the verification on spy fails");
   }

   public doInvoke()
   {
        m_invoker.invoke();
   }

}

==========================

public class FooTests
{
   Foo m_foo = Mockito.spy(new Foo());
   @Test
   public void testVerifyBarIsInvoked()
   {
       m_foo.doInvoke();

       //THIS VERIFICATION FAILS.... SAYS BAR ISN'T INVOKED; mockito 1.9.5
       Mockito.verify(m_foo, times(1)).bar();
   }
}

Original issue reported on code.google.com by Saivivek...@gmail.com on 25 Jul 2015 at 7:26

GoogleCodeExporter commented 9 years ago
I meant,

m_invoker = new Invoker(){
      public void invoke()
     {
         bar();
     }
};

in Foo's constructor

Original comment by Saivivek...@gmail.com on 25 Jul 2015 at 7:29