title: JUnit Easymock Unexpected method call
body: <p>I'm trying to setup a test in JUnit w/ EasyMock and I'm running into a small issue that I can't seem to wrap my head around. I was hoping someone here could help. </p>
  
  <p>Here is a simplified version of the method I'm trying to test:</p>
  
  <pre><code>public void myMethod() {
      //(...)
      Obj myObj = this.service.getObj(param);
      if (myObj.getExtId() != null) {
        OtherObj otherObj = new OtherObj();
        otherObj.setId(myObj.getExtId());
        this.dao.insert(otherObj);
      }
      //(...)
  }
  </code></pre>
  
  <p>Ok so using EasyMock I've mocked the <code>service.getObj(myObj)</code> call and that works fine. </p>
  
  <p>My problem comes when JUnit hits the <code>dao.insert(otherObj</code>) call. EasyMock throws a <code>*Unexpected Method Call*</code> on it. </p>
  
  <p>I wouldn't mind mocking that dao in my test and using <code>expectLastCall().once();</code> on it, but that assumes that I have a handle on the "otherObj" that's passed as a parameter at insert time... 
  Which of course I don't since it's conditionally created within the context of the method being tested.</p>
  
  <p>Anyone has ever had to deal with that and somehow solved it?</p>
  
  <p>Thanks.</p>