title: Easymock: Issue Mocking void DAO method - Unexpected method call
body: <p><strong>Found a workaround. See solution at the bottom</strong></p>
  
  <p>Ok I have been in EasyMock jail all day and I need some help getting out.
  I have a void save() method I am mocking out.</p>
  
  <pre><code>public void save(PurchaseOrder po);
  </code></pre>
  
  <p>PurchaseOrder is an abstract class that has two children</p>
  
  <pre><code>USPurchaseOrder
  CAPurchaseOrder
  </code></pre>
  
  <p>Here's my code in the JUnit test</p>
  
  <pre><code>MyDAO myDAO = createMock(MyDAO.class);
  PurchaseOrder usPurchaseOrder = new USPurchaseOrder(msgUS);
  myDAO.save(usPurchaseOrder);
  expectLastCall().atLeastOnce();
  
  PurchaseOrder caPurchaseOrder = new CAPurchaseOrder(msgCA);
  myDAO.save(caPurchaseOrder);
  expectLastCall().atLeastOnce();
  
  replay(myDAO);
  
  //execute code that uses DAO
  </code></pre>
  
  <p>I get the following error: Unexpected method call MyDAO.save(USPurchaseOrder@1a70b8):</p>
  
  <p>The only problem here is that the DAO signature does not require a USPurchaseOrder, only a PurchaseOrder, which is what I am passing in.</p>
  
  <p>Even doing this produces the same error</p>
  
  <pre><code>myDAO.save(new USPurchaseOrder(msgUS));
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p><strong>Workaround</strong>
  Ok, I kept plugging away at this and while I don't understand why I am getting the error, I added the anyObject() to the code to get it to work.</p>
  
  <pre><code>MyDAO myDAO = createMock(MyDAO.class);
  
  myDAO.save(anyObject(OrderRequest.class));
  
  myDAO.save(anyObject(OrderRequest.class));
  
  replay(myDAO);
  
  //execute code that uses DAO
  </code></pre>