title: Why am I getting MissingMethodInvocationException?
body: <p>I've a service that invokes a DAO through Spring, so now I'm trying to do some testing using mock. Here is my context:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:task="http://www.springframework.org/schema/task"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd" 
          default-autowire="byName"&gt;
  
      &lt;import resource="classpath*:invoice-core-config-test.xml" /&gt;
      &lt;import resource="classpath:invoice-cfd-config.xml" /&gt;
      &lt;import resource="classpath*:invoice-almacenaje-config.xml" /&gt;
      &lt;import resource="classpath*:invoice-firmadigital-config.xml" /&gt;
      &lt;bean id="comprobanteServiceMock" class="org.mockito.Mockito" factory-method="mock"&gt;
          &lt;constructor-arg type="java.lang.Class"
              value="com.praxis.fact.core.entity.Comprobante" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>And here is my service class:</p>
  
  <pre><code>public class ComprobanteServiceImpl implements ComprobanteService {
  
      private static final Logger logger = LoggerFactory.getLogger(ComprobanteServiceImpl.class);
  
      /**
       * Dao de comprobantes que se va a utilizar para el servicio.
       */
      @Autowired
      @Qualifier("comprobanteDao")
      private ComprobanteDao comprobanteDao;
  
  
      @Override
      public List&lt;MedioGeneracion&gt; getMediosGeneracion() throws BusinessException {
          try {
              if (comprobanteDao == null) {           
                  ClassPathXmlApplicationContext ctx = new 
                  ClassPathXmlApplicationContext("classpath:invoice-core-config-test.xml");
                  comprobanteDao = (ComprobanteDao) ctx.getBean("comprobanteDao");
              }           
              return comprobanteDao.getMediosGeneracion();
          } catch (Exception daoExc) {
              throw new BusinessException(CodigoError.ERROR_NEGOCIO, "Error al obtener los medios de generacion", daoExc);
          }
      }
  }
  </code></pre>
  
  <p>And finally here is my testing method:</p>
  
  <pre><code>@Test
  public void testSalvarComprobanteConMedioGeneracion() {
      try {
          ClassPathXmlApplicationContext ctx = new 
                  ClassPathXmlApplicationContext("classpath:context.xml");
          this.comprobanteTestBean = (Comprobante) ctx.getBean("comprobanteTestBean");
          this.comprobanteService = (ComprobanteService)ctx.getBean("comprobanteService");
          MockitoAnnotations.initMocks(this);
          when(comprobanteService.saveComprobante(comprobanteTestBean)).thenReturn(obtenerRespuesta());
      } catch (BusinessException e) {
          logger.error("Error al iniciar el setup() de la prueba", e.getMessage());
      } catch (InitializationError e) {
          logger.error("Ejecuta con: -DfactElectronica.home=C:/tmp");
      }   
  } 
  
  private Long obtenerRespuesta() {
      System.out.println("obtenerRespuesta"); 
      return new Long(1);
  }
  </code></pre>
  
  <p>So when I run my test I´m getting:
      org.mockito.exceptions.misusing.MissingMethodInvocationException: 
  when() requires an argument which has to be 'a method call on a mock'.
  For example:
      when(mock.getArticles()).thenReturn(articles);</p>
  
  <p>Also, this error might show up because:
  1. you stub either of: final/private/equals()/hashCode() methods.
     Those methods <em>cannot</em> be stubbed/verified.
  2. inside when() you don't call method on mock but on some other object.</p>
  
  <pre><code>at com.praxis.fact.cfd.business.impl.ComprobanteServiceImplTests.testSalvarComprobanteConMedioGeneracion(ComprobanteServiceImplTests.java:242)
  </code></pre>
  
  <p>Why is that error happening?
  Thanks in advance.</p>