I made a mistake. There is not createNativeQuery - there is createNamedQuery. Once I corrected the typo I was able to mock Query and EntityManager.
I'm trying to write a test to return a list from method calls to EntityManager. The line of code is:
entityManager.createNativeQuery("myQuery").setParameter(1, param1).getResultList()

Since createNativeQuery returns a Query, the setParameter is called on that. But so far I can't figure out how to set up the mocks to allow me to create a mocked Query that I can return my test list from when I call getResultList.

I've been looking at different syntax possibilities, but can't find a correct match. It would be easier if all the method calls were on entityManager and not on an object that it returns.

Forgot to mention that the error I keep getting when trying to mock this is "can't setParameter on null object".

In eBook version, Chapter 1, the binary search code just above the exercises has
mid = (low + high)
which is incorrect. It's missing the division by 2.
Thank you!
I've come across some Spock code that is of the form:
 with (object1, {
              member2 == SomeEnum.ENTRY1.name()
              member3 == SomeEnum.ENTRY2.name()

Here the with clause has an object followed by a comma before the opening brace. What is the difference, if any, of having a comma follow the object being evaluated?