title: In Spock unit test mocked method is not being called
body: <p>I'm trying to implement unit test using <a href="http://spockframework.org/" rel="nofollow noreferrer">Spock framework</a> this is what my test looks like:</p>
  
  <pre><code>    def setup() {
          scrollableResultsMock = Mock(ScrollableResults)
          paymentRepositoryMock = Mock(PaymentRepository)
  
          paymentRegistryService = new PaymentRegistryService(paymentRepositoryMock)
      }
  
      @Unroll
      def 'should correctly process'() {
          given:
          paymentRepositoryMock.findUnconfirmedTransactions(_ as LocalDate, _ as Days) &gt;&gt; scrollableResultsMock
          ...
      }
  </code></pre>
  
  <p>Here is class in which I'm trying to inject mocked object:</p>
  
  <pre><code>@Service
  open class PaymentRegistryService
  @Autowired
  constructor(
          val paymentRepository: PaymentRepository
  ) {
  
      @Transactional
      open fun parseRegistryFileStream(input: InputStream): LinkedList&lt;Pair&lt;Long, String&gt;&gt; {
          ...
          val registry = paymentRepository.findUnconfirmedTransactions(start, PERIOD)
          ...
      }
  }
  </code></pre>
  
  <p>While running test instead of calling my method real <code>paymentRepository</code> method is being called. I don't understand what could be the reason. <code>LocalDate</code> and <code>Days</code> are from <a href="http://joda-time.sourceforge.net/" rel="nofollow noreferrer">Joda time</a> and finally this is <code>paymentRepository</code> class:</p>
  
  <pre><code>@Repository
  @Transactional
  open class PaymentRepository : AbstractRepository&lt;Payment, Long&gt;(Payment::class.java) {
  
      fun findUnconfirmedTransactions(start: LocalDate, days: Days): ScrollableResults = criteria().add(
              and(
                      eq("isConfirmed", false),
                      ge("transactionDateTime", start),
                      lt("transactionDateTime", start.plus(days))
              )).setCacheMode(CacheMode.IGNORE).scroll(ScrollMode.FORWARD_ONLY)
  
  }
  </code></pre>