title: groovy spock mocking spring autowired beans
body: <p>I have bean:</p>
  
  <pre><code>@Service
  public class EQueueBookingService {
  
      @Autowired
      public EQueueBookingClient eQueueBookingClient;
  </code></pre>
  
  <p>And I try to write some test for this bean EQueueBookingService using Spock.
  <a href="https://code.google.com/p/spock/wiki/SpockBasics" rel="nofollow">https://code.google.com/p/spock/wiki/SpockBasics</a></p>
  
  <p>My mock is</p>
  
  <pre><code>class EQueueBookingServiceTest extends Specification {
  
  @Autowired
  EQueueBookingService testedService;
  
  EQueueBookingClient eQueueBookingClient = Mock(EQueueBookingClient);
  
  def setup() {
      testedService.eQueueBookingClient = eQueueBookingClient;
  }
  </code></pre>
  
  <p>and test method:</p>
  
  <pre><code>...
  setup:
  CancelBookingResponse response = new CancelBookingResponse();
  ...
  eQueueBookingClient.cancelBooking(_, _) &gt;&gt; response;
  when:
  
  def result = testedService.cancelBooking(request);
  
  then:
  result != null &amp;&amp; result.bookId == bookId
  </code></pre>
  
  <p>Why eQueueBookingClient doesn't mock?</p>
  
  <p>When I debug it: in test - I see Mock instance, when I go to method - I see real bean instance.</p>
  
  <p>Thanks a lot!</p>