spockframework / spockframework/spock

Spock InteractionBuilder doesn't work with spread (*) operator

Open
#1,365 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

Unable to pass spread operator (*) to interaction verification.

To Reproduce

I have a service that is just a wrapper for another class:

class WrapperClass {
    InternalClass internalClass;

    public void firstMethod(String firstArg, String secondArg) {
        internalClass.firstMethod(firstArg, secondArg);
    }

    public void secondMethod(String firstArg, String secondArg, long thirdArg) {
        internalClass.secondMethod(firstArg, secondArg, thirdArg);
    }
}
class InternalClass {

    public void firstMethod(String firstArg, String secondArg) {
        // do smth
    }

    public void secondMethod(String firstArg, String secondArg, long thirdArg) {
        // do smth
    }
}

I am writing the following test that dynamically verifies all wrapper methods:

class WrapperClassTest extends Specification {

    def innerClass = Mock(InnerClass)
    def wrapper = new WrapperClass(innerClass: innerClass)

    @Unroll
    def "test #methodName with args #args"() {
        when:
            wrapper."$methodName"(*args)

        then:
            1 * innerClass."$methodName"(*args)

        where:
            methodName      | args
            'firstMethod'        | ['firstArg', 'secondArg']
            'secondMethod'   | ['firstArg', 'secondArg', 123L]
    }
}

But I am getting the following exception:

groovy.lang.MissingMethodException: No signature of method: org.spockframework.mock.runtime.InteractionBuilder.addEqualArg() is applicable for argument types: (java.lang.String, java.lang.String) values: [firstArg, secondArg]
Possible solutions: addEqualArg(java.lang.Object)
Expected behavior

The test should pass.

Actual behavior

Test fails with the following exception:

groovy.lang.MissingMethodException: No signature of method: org.spockframework.mock.runtime.InteractionBuilder.addEqualArg() is applicable for argument types: (java.lang.String, java.lang.String) values: [firstArg, secondArg]
Possible solutions: addEqualArg(java.lang.Object)
Java version

java version "1.8.0_251"

Buildtool version

Gradle 6.5

What operating system are you using

Windows

Dependencies

spock 1.3 - groovy 2.4

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided WrapperClassTest example with Spock 1.3 and inspect the InteractionBuilder.addEqualArg() call named in the exception. The issue is done when interaction verification accepts the spread arguments and the dynamic wrapper test passes without MissingMethodException.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.