Krzysztof
Krzysztof

Reputation: 2082

Why spock mocking void method does not work

In specification I want to mock class:

com.univocity.parsers.csv.CsvParser

I try to do this like this:

        parser = Stub() 
        parser.stopParsing() >> null

or

        parser.stopParsing() >>  {}

Nothing works.

Always original class method is called.

I tried it with 2 and 3 version of Groovy and correct Spock version.

a) what I need to do, to make this work?

b) where I can find in documentation info about why original class method is called for Stub or Mock?

Upvotes: 0

Views: 192

Answers (1)

Leonard Brünings
Leonard Brünings

Reputation: 13242

Spock cannot mock final classes and/or methods and CsvParser as well as stopParsing() are final. You can try using the spock mockable extension to make those classes/methods non-final.

Upvotes: 1

Related Questions