title: How to mock EntityManager and Query with Spock?
body: <p>Using spock I need to mock the calls to <code>EntityManager</code>/<code>Query</code>. The line of code I'm trying to mock is:</p>
  
  <pre><code>entityManager.createNativeQuery("nativeQuery").setParameter(1, param1).getResultList()
  </code></pre>
  
  <p>The mock of <code>entityManager.createNativeQuery</code> returns a null <code>Query</code> object. That then causes a failure because you can't call a method on a null object. And I consequently I can't mock the return of a result set list.</p>
  
  <p>I've tried breaking the statement down into separate ones and accompanying mocks, but that hasn't worked either because I still end up with a null Query.</p>
  
  <p>I don't know if I've got tunnelvision on this right now, or if this can't be mocked - at least with Spock.</p>
  
  <p>All help appreciated!</p>