title: Mocking DataSource for JdbcTemplate with Mockito
body: <p>I'm trying to test a class in a Spring project. I would like to make as many changes as possible in the test class vs. the dao class so that I don't have to retest all sorts things because of a change.</p>
  
  <p>The class I'm working with has a <code>JdbcTemplate template</code> class variable that is instantiated by the following:</p>
  
  <pre><code>setJdbcTemplate(DataSource dataSource) {
      this.template = new JdbcTemplate(dataSource);
  }
  </code></pre>
  
  <p>The method I would like to test makes a <code>template.query(&lt;code&gt;)</code> to run a defined SQL query and return the results to a list. </p>
  
  <p>I created the following in my test case, but I'm not sure how to put it into use. Can I make the following code return a certain list of Strings using Mockito?</p>
  
  <pre><code>DataSource mockedDataSrc = Mockito.mock(DataSource.class);
  customerClassDao.setJdbcTemplate(mockedDataSrc); 
  </code></pre>
  
  <p>Can I somehow use the <code>when</code> or another command to set what I want to be returned to the JdbcTemplate's <code>.query</code> call?</p>