title: junit testing with mock objects: stub inner function calls
body: <p>So I was trying to test <code>ping()</code> method and make sure that it calls <code>connect()</code> and <code>disconnect()</code>. I mocked the object <code>foo</code> and an object <code>Connection</code>. Then I did <code>stub(mockFoo.connect()).toReturn(mockConn)</code> hoping that then <code>ping()</code> should return true for me to assert. However, somehow this stubbing is not going through. I'm suspecting that maybe when connect is called internally, mockFoo didn't actually invoke <code>connect()</code>, hence didn't return the mock Connection, but I'm not sure. </p>
  
  <pre><code>public class foo{
      public boolean ping(){
          bool ping = false; 
          Connection conn = null;
          try{
             conn = connect();
             ping = true;
          }catch(Exception e){
          }finally{
             disconnect(conn);
          }
          return ping;
      }
  
      public Connection connect(){
          //some implementation
          return connect
      }
  </code></pre>