title: Parameter named query testing with mockito
body: <p>I want to write a Junit test for my dao, but I have a problem. Here is the method I want to test:   </p>
  
  <pre><code> public boolean boo(final String param) {
              final Query query = this.entityManager.createNamedQuery("queryName");
              query.setParameter(1, param);
              boolean isExists = false;
              if(query.getResultList().size() != 0) {
                  isExists = true;
              }
              return isExists;
          }
  </code></pre>
  
  <p>The problem with this method is :</p>
  
  <pre><code>query.setParameter(1, param);
  </code></pre>
  
  <p>When I write something like : </p>
  
  <pre><code>   @Test
      public void test() {        
          when(entityManager.createNamedQuery(queryName)).thenReturn(query);
          when(query.getResultList()).thenReturn(new ArrayList());
          //when(query.setParameter(1,project.getName())).thenCallRealMethod();
          projectDao.boo(name);
  
      }
  </code></pre>
  
  <p>The query and entityManager are mocked.
  I have NPE, and this is not a surprise, and I cannot call the method because the query is and interface. 
  So could somebody tell me the best way to set parameters in NamedQueries while testing?</p>