Ambiguous method overloading for method in Grails Spock Test

In case you run into the following exception when using mocks in a Spock test:

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Integer#multiply.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
	[class java.lang.Character]
	[class java.lang.Number]

It might be that the mistake is simply that you need to use the rightshift operator (>>) instead of leftshift (<<) for adding the mocked return value. Here's how I produced the (not really obvious) error:

        service.publicRESTCategoriesService = Mock(PublicRESTCategoriesService)
        1 * service.publicRESTCategoriesService.getCustomDesignsCategories(12L, false, ‘test’) << [1]  // '<<' is wrong, use '>>’
This entry was posted in Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please solve this little equation for verifying that you\'re human *