Skip to content
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

JavaReflectionImposteriser and Scala #74

Open
nargov opened this issue May 8, 2015 · 2 comments
Open

JavaReflectionImposteriser and Scala #74

nargov opened this issue May 8, 2015 · 2 comments

Comments

@nargov
Copy link

nargov commented May 8, 2015

Hi,

I've been writing a small integration library between JMock and specs2, since we love JMock here at Wix, but we write mostly in Scala now.
I encountered an issue where the JavaReflectionImposteriser would fail to create a mock from a Scala trait that contains a function that returns a Scala Set.
It fails because the Imposteriser uses JDKs Proxy which is unable to create the instance. This is due to Set having two apply methods:

apply(T): Boolean

and

apply(T*:): CC[T]

Since Java ignores Scala's way of creating parameter lists, it things both methods have the same signature but with different return types.

I have worked around this by creating a new Imposteriser, which uses the JavaReflectionImposteriser, and if it fails because of that error, uses the ClassImposteriser instead.

I just thought you guys might find this interesting.

@olibye
Copy link
Member

olibye commented May 12, 2015

Thanks for the tip. If I understand you correctly you're, not raising an issue with JMock?
I nearly always use the ClassImposteriser.

It looks like we should add your Specs2-JMock project as a link in our readme.

@nargov
Copy link
Author

nargov commented May 12, 2015

You're correct, this is more of an issue with Scala-Java interop, but I just thought it had some bearing here, perhaps for documentation purposes.

I do like that the JavaReflectionImposteriser is the default and that using the ClassImposteriser has to be a conscious decision, since it doesn't work on Classes, and reminds me that I should strive to use mocking on interfaces, rather than concrete classes.

And that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants