New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"IllegalArgumentException: source and target are not compatible" if Spy is assigned to variable with interface type #822

Closed
reftel opened this Issue Feb 15, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@reftel

reftel commented Feb 15, 2018

Issue description

When a Spy with a provided instance is created and assigned to a variable that is explicitly declared as having an interface as type, creating the spy fails with an IllegalArgumentException in ReflectionUtil.deepCopyFields . If the variable is explicitly declared as having a class as type, or is defined using "def", then creating the spy works as intended.

The stack trace produced is:

java.lang.IllegalArgumentException: source and target are not compatible.

	at org.spockframework.util.ReflectionUtil.deepCopyFields(ReflectionUtil.java:248)
	at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:62)
	at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:38)
	at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:42)
	at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:46)
	at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:291)
	at org.spockframework.lang.SpecInternals.SpyImpl(SpecInternals.java:180)
	at com.reftel.magnus.spockspytestcase.CallerTest.should not call expensive method - interface(CallerTest.groovy:37)

How to reproduce

See testcase at https://github.com/reftel/spock-spy-testcase/tree/master

Additional Environment information

Spock version

Spock 1.2-groovy-2.4-20180205.215134-43

Java/JDK

java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Groovy version

2.4.13

@leonard84

This comment has been minimized.

Member

leonard84 commented Feb 15, 2018

Yes there is an issue with the inferredType for Spy.

@leonard84 leonard84 added the bug label Feb 15, 2018

leonard84 added a commit to leonard84/spock that referenced this issue Aug 9, 2018

@leonard84 leonard84 closed this in d3a493d Aug 9, 2018

@reftel

This comment has been minimized.

reftel commented Aug 9, 2018

Yup, that solved it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment