title: Matching JdbcTemplate update method with Mockito
body: <p>I am trying to match this method which I have used in my Dao class. But I always get the following exception indicating that the call was not made on the method.</p>
  
  <p>It's either the method is not matched, or I am doing something wrong.</p>
  
  <pre><code>String pSql = "SELECT * FROM employee";
  Object[] pArgs = new Object[] {""};
  int[] pArgTypes =  new int[] {};
  
  /* Return 1 when the call to update() is made indicating a successful database update */
  when(mJdbcTemplate.update(anyString(), aryEq(pArgs), aryEq(pArgTypes))).thenReturn(1);
  </code></pre>
  
  <p>Here is the stack trace of the exception:</p>
  
  <pre><code>Wanted but not invoked:
  jdbcTemplate.update(&lt;any&gt;, &lt;any&gt;, &lt;any&gt;);
  -&gt; at com.test.GenericDaoJdbcImplTest$WhenInsertUpdateDeleteIsCalledWith.successfulUpdateShouldReturnTrue(GenericDaoJdbcImplTest.java:197)
  
  However, there were other interactions with this mock:
  -&gt; at com.test.GenericDaoJdbcImplTest.insertUpdateDelete(GenericDaoJdbcImpl.java:121)
  
      at org.mockito.exceptions.Reporter.wantedButNotInvoked(Reporter.java:269)
      at org.mockito.internal.verification.checkers.MissingInvocationChecker.check(MissingInvocationChecker.java:42)
      at org.mockito.internal.verification.Times.verify(Times.java:36)
      at org.mockito.internal.verification.MockAwareVerificationMode.verify(MockAwareVerificationMode.java:21)
      at org.mockito.internal.MockHandler.handle(MockHandler.java:80)
      at org.mockito.internal.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:36)
      at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:48)
      at org.springframework.jdbc.core.JdbcTemplate$$EnhancerByMockitoWithCGLIB$$92326890.update(&lt;generated&gt;)
      at com.test.GenericDaoJdbcImplTestTest$WhenInsertUpdateDeleteIsCalledWith.successfulUpdateShouldReturnTrue(GenericDaoJdbcImplTest.java:197)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>
  
  <p>My <code>GenericDaoJdbcImplTest</code> is an abstract class. Here is the class which I am testing.</p>
  
  <pre><code>public abstract class GenericDaoJdbcImpl&lt;MODEL, PRIMARYKEY extends Serializable&gt;
          implements GenericJdbcDao&lt;MODEL, PRIMARYKEY&gt; {
  
      @Autowired
      @Qualifier(value = "jdbcTemplate")
      private JdbcTemplate mJdbcTemplate;
  
      private Class&lt;MODEL&gt; mType;
  
      public JdbcTemplate getJdbcTemplate() {
          return mJdbcTemplate;
      }
  
      public void setJdbcTemplate(final JdbcTemplate pJdbcTemplate) {
          this.mJdbcTemplate = pJdbcTemplate;
      }
  
      public GenericDaoJdbcImpl(final Class&lt;MODEL&gt; pType) {
          this.mType = pType;
      }
  
      public abstract MODEL add(final MODEL mModel);
  
      public abstract MODEL modify(final MODEL mModel);
  
      public abstract MODEL read(PRIMARYKEY pId);
  
      public abstract List&lt;MODEL&gt; list();
  
      public abstract void delete(PRIMARYKEY pId);
  
      @Override
      public boolean insertUpdateDelete(final String pSql, final Object[] pArgs,
              final int[] pArgTypes) {
  
          Assert.hasLength(pSql, "No SQL provided to execute");
          Assert.notNull(pArgs, "No data provided to insert/update/delete");
          Assert.notNull(pArgTypes, "No data types provided for");
          Assert.isTrue(pArgs.length == pArgTypes.length, "Mis-match in data and data type count");
  
          return (mJdbcTemplate.update(pSql, pArgs, pArgTypes) &gt; 0);
      }
  }
  </code></pre>