title: Mock injection in Spring using Spock not working
body: <p>So I am using the <code>Spring=Retry</code> library in my project and trying to run a test case for that. 
  I am loading the service DCS as a bean that returns a new object.
  Its two dependencies SSService and AttributeService are loaded as beans as well. But these two are mocks.
  When my test spec runs i can see inside DCS.execute that the mocks are there alright. But the interactions on them like <code>1 *  SSService.read(_ as LComponent,_) &gt;&gt; mockSimpleSettingCommResult</code> is not taking effect resulting in a null value instead of the value i want it to return.</p>
  
  <pre><code>@ContextConfiguration(classes = [SpringRetryConfig])
  class DCSISpec extends Specification {
  
      @Autowired
      DCS  DCS
      @Autowired
      SSService sSService
      @Autowired
      AttributeService attributeService
  
      def setup() {
  //        DCS.SSService = SSService
  //        DCS.attributeService = attributeService
      }
  
      def "execute failure"(){
          setup:
          DataCollectionDataSet mockDataCollectionDataSet = Mock(DataCollectionDataSet)
          LComponent mockLComponent = Mock(LComponent)
          SSCommResult mockSimpleSettingCommResult = Mock(SSCommResult)
  
          ReflectionTestUtils.setField(DCS, "SSService", SSService)
          ReflectionTestUtils.setField(DCS, "attributeService", attributeService)
  
          when:
          DCS.execute(mockLComponent, mockDataCollectionDataSet)
  
          then:
          1 *  mockSimpleSettingCommResult.getDegreeOfSuccess() &gt;&gt; SSCommResult.DegreeOfSuccess.FAILURE
          1 * mockDataCollectionDataSet.getNamespace() &gt;&gt; DCSNamespace.xyz
          1 * mockDataCollectionDataSet.getDataElements() &gt;&gt; ["FOO": "BAR"]
          1 *  SSService.read(_ as LComponent,_) &gt;&gt; mockSimpleSettingCommResult
  
          3 * DCS.execute(_ as LComponent, _ as DataCollectionDataSet)
      }
      @Configuration
      @EnableRetry
      public static class SpringRetryConfig {
          @Bean
          public SSService SSService() {
              Mockito.mock(SSService)
          }
          @Bean
          public AttributeService attributeService() {
              Mockito.mock(AttributeService)
          }
          @Bean
          public DCS  DCS() {
             return new DCS();
          }
      }
  }
  </code></pre>
  
  <p>This is the exception i get when trying to use plain Mockito ,</p>
  
  <pre><code>java.lang.NullPointerException
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
      at com.lexmark.mps.cma.service.DataCollectionRetryTest.test_retry(DataCollectionRetryTest.groovy:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:224)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
  </code></pre>