title: Why is sessionFactory not injected for unit test using Grails 3.2?
body: <p>I'm running into an issue where a unit test that extends HibernateSpec is failing due to the <code>sessionFactory</code> not being injected into the service under test. Whenever a method on the <code>sessionFactory</code> is called during the test, I get a <code>NullPointerException</code> (e.g. <code>java.lang.NullPointerException: Cannot invoke method getClassMetadata() on null object</code>) and the test subsequently fails.</p>
  
  <p>I'm using Grails 3.2.4 and Hibernate 5.</p>
  
  <p>This was working when the test used <code>@TestMixin(HibernateTestMixin)</code>, but it looks like with some updates, the mixin is deprecated and suggests using <code>HibernateSpec</code> instead.</p>
  
  <p>Here's a snippet from my test:</p>
  
  <pre><code>class TestDatabaseServiceSpec extends HibernateSpec {
      def setup() {
      }
  
      def cleanup() {
      }
  
      void "test method"() {
          when: 
          service.method() 
  
          then:
          true
      }
  }
  </code></pre>
  
  <p>And here is a snippet from the service under test:</p>
  
  <pre><code>void method() {
  ...
    TABLE_NAMES.add(sessionFactory.getClassMetadata('MyDomain').tableName)
  ...
  }
  </code></pre>
  
  <p>I have tried to set <code>service.sessionFactory</code> in <code>setup</code> method as well as <code>setupSpec</code> method with the <code>sessionFactory</code> available in the test, but that did not help unfortunately. I have thought about using an integration test, but I would really like to see if I can continue to have this unit test work as it was before. Does anyone know if I am I doing something incorrectly or if there is a workaround/solution for this?</p>
  
  <p>Thank you!</p>