title: Partial-mocking considered bad practice? (Mockito)
body: <p>I'm unit-testing a business object using Mockito. The business object uses a DAO which normally gets data from a DB. To test the business object, I realized that it was easier to use a separate in-memory DAO (which keeps data in a HashMap) than to write all the </p>
  
  <pre><code>when(...).thenReturn(...)
  </code></pre>
  
  <p>statements. To create such a DAO, I started by partial-mocking my DAO interface like so:</p>
  
  <pre><code>when(daoMock.getById(anyInt())).then(new Answer() {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
          int id = (Integer) invocation.getArguments()[0];
          return map.get(id);
      }
  });
  </code></pre>
  
  <p>but it occurred to me that it was easier to just implement a whole new DAO implementation myself (using in-memory HashMap) without even using Mockito (no need to get arguments out of that InvocationOnMock object) and make the tested business object use this new DAO.</p>
  
  <p>Additionally, I've read that partial-mocking was considered bad practice. My question is: is what I'm doing a bad practice in my case? What are the downsides? To me this seems OK and I'm wondering what the potential problems could be.</p>