title: How to mock Autowired objects(java) and inject inside to a spy object in Spock
body: <p>How I can inject mock objects into a spied instance in Spock?</p>
  
  <p>Example:</p>
  
  <p>TestClass</p>
  
  <pre><code>class Service {
  
       @AutoWired
       private Util util;
  
       public void testMethod(int a, int b) {
  
           int c = sum(a,b);
           util.format(c);
       }
  
       private int sum(int a, int b) {
          ......
       }
  }
  </code></pre>
  
  <p>Spock:</p>
  
  <pre><code>def "testMethod with valid inputs"() {
  
      given:
         def serviceSpy    = Spy(Service)
         //spy.util          = Mock(Util) I can't do this
         spy.sum(_,_) &gt;&gt; 2
  
      ......
  }
  </code></pre>
  
  <p>So, My doubt is how I can inject a mock object into the spied instance?</p>
  
  <p>I tried to spy the existing instance, but it's not stubbing the method that's in the test class.</p>
  
  <p>Could someone suggest me, what I can do here? Or Can I solve it easily using Junit(Mockito)?</p>