SpyStatic trying to expand varargs when Mockito already expanded varargs
meestchoo opened this issue · comments
Describe the bug
When using SpyStatic + stubbing static method with varargs, Spock is trying to expand last method call argument, but Mockito already expanded varargs (check constructor of org.mockito.internal.invocation.InterceptedInvocation). Using Mockito 5.17.0.
To Reproduce
import spock.lang.Specification
class SpyStaticTest extends Specification {
def "test"() {
given:
SpyStatic(SomeStaticClass)
SomeStaticClass.someStaticVarargsMethod("test") >> true
SomeStaticClass.someStaticVarargsMethod("test2") >> false
when:
def result = SomeStaticClass.someStaticVarargsMethod("test2")
then:
!result
}
}
class SomeStaticClass {
static boolean someStaticVarargsMethod(String str, String... varargs) {
return true
}
}
Expected behavior
It shouldn't take the last parameter varargs array.
Actual behavior
java.lang.IllegalArgumentException: Argument is not an array
at org.spockframework.mock.constraint.PositionalArgumentListConstraint.expandVarArgs(PositionalArgumentListConstraint.java:91)
at org.spockframework.mock.constraint.PositionalArgumentListConstraint.isSatisfiedBy(PositionalArgumentListConstraint.java:46)
at org.spockframework.mock.runtime.MockInteraction.matches(MockInteraction.java:69)
at org.spockframework.mock.runtime.MockInteractionDecorator.matches(MockInteractionDecorator.java:46)
at org.spockframework.mock.runtime.InteractionScope.match(InteractionScope.java:94)
at org.spockframework.mock.runtime.MockController.handle(MockController.java:47)
at org.spockframework.mock.runtime.JavaMockInterceptor.intercept(JavaMockInterceptor.java:83)
at org.spockframework.mock.runtime.mockito.MockitoMockMakerImpl$SpockMockHandler.handle(MockitoMockMakerImpl.java:265)
at org.mockito.internal.creation.bytebuddy.access.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:84)
at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleStatic(MockMethodAdvice.java:150)
at SomeStaticClass.someStaticVarargsMethod(SpyStaticTest.groovy:20)
at SpyStaticTest.test(SpyStaticTest.groovy:11)
Java version
Tested on JDK 17 and 24.
Buildtool version
Tested on Maven 3.9.7
What operating system are you using
Windows
Dependencies
org.example:spock-static-class-test:jar:1.0-SNAPSHOT
+- org.apache.groovy:groovy:jar:4.0.26:compile
+- org.spockframework:spock-core:jar:2.4-M6-groovy-4.0:test
| +- org.junit.platform:junit-platform-engine:jar:1.12.2:test
| | +- org.opentest4j:opentest4j:jar:1.3.0:test
| | +- org.junit.platform:junit-platform-commons:jar:1.12.2:test
| | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
| +- org.hamcrest:hamcrest:jar:3.0:test
| \- io.leangen.geantyref:geantyref:jar:1.3.16:test
\- org.mockito:mockito-core:jar:5.17.0:test
+- net.bytebuddy:byte-buddy:jar:1.15.11:test
+- net.bytebuddy:byte-buddy-agent:jar:1.15.11:test
\- org.objenesis:objenesis:jar:3.3:test
Additional context
No response
@meestchoo I could reproduce your issue with:
91c4034
I do not yet have a quick and good solution for the problem and I am currently not able to work on the issue.
So you need to be a bit patient.
Or if you have time give it a shot to fix it.