title: How to use thenAnswer with method which returns void
body: <p>I want to unit test following method   </p>
  
  <pre><code>public void addRecord(Record record)  
  {  
     Myclass newObj = new Mycalss();  
     // It creates newObj object, set some values using record object.  
     // and it adds the newObj in daatbase.
     dataReqDao.persist(newObj);
  }    
  </code></pre>
  
  <p>I have mocked <code>dataReqDao.persist</code> method but how can I verify if right values are copied into newObj object? I want to get the newObj object.   </p>
  
  <p>I think <code>thenAnswer</code> will be the appropraite method to retrieve newObj ie method arguments but dont know how to use it method which returns void.     </p>
  
  <p><strong>Update:</strong><br>
  I tried </p>
  
  <pre><code>doAnswer(new Answer&lt;Myclass&gt;() {
                public Myclass answer(InvocationOnMock invocation) {
                    Object[] args = invocation.getArguments();
                    return (Myclass)args[0];
                }
  
          }).when(dataReqDao.persist(any(Myclass.class)));
  </code></pre>
  
  <p><strong>EDIT:</strong><br>
  It should be (Thanks David)     </p>
  
  <pre><code> doAnswer(new Answer&lt;Myclass&gt;() {
                    public Myclass answer(InvocationOnMock invocation) {
                        Object[] args = invocation.getArguments();
                        return (Myclass)args[0];
                    }
  
              }).when(dataReqDao).persist(any(Myclass.class));
  </code></pre>