title: how to replace mock function with new funciton in java
body: <p>I am write UT with Mockito, and I want replace my mock function(which DB select operation)</p>
  
  <pre><code>class DataBaseSelect {
      List&lt;Long&gt; selectDataFromDB(Long key){
           List&lt;Long&gt;  result  = db.select(key);
           return result;
      }
  }
  </code></pre>
  
  <p>with new function (mock db select using map) I wrote in Test class;</p>
  
  <pre><code>class MapSelect {
      List&lt;Long&gt; selectDataFromMap(Long key){
           List&lt;Long&gt; result = map.get(key);
           return result;
      }
  }
  </code></pre>
  
  <p>and I want return the right value with right key input</p>
  
  <p>I try to do this using ArgumentCaptor as below, but it did not work as I want</p>
  
  <pre><code>ArgumentCaptor&lt;Long&gt; argumentCaptor = ArgumentCaptor.forClass(Long.class);
  Mockito.when(dataBaseSelect.selectDataFromDB(argumentCaptor.capture())).thenReturn(MapSelect.selectDataFromMap(argumentCaptor.getValue()));
  //some thing else here , 
  </code></pre>
  
  <p>I want when call dataBaseSelect.selectDataFromDB, it will be mock and then return result from MapSelect.selectDataFromMap and argument is passed from dataBaseSelect.selectDataFromDB</p>