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

Is it possible to use proxy mocks with generated mocks? #15

Closed
takezoe opened this issue May 13, 2012 · 6 comments
Closed

Is it possible to use proxy mocks with generated mocks? #15

takezoe opened this issue May 13, 2012 · 6 comments

Comments

@takezoe
Copy link

takezoe commented May 13, 2012

My environment is Scala 2.9.1, sbt 0.11.2 and ScalaMock 2.2.

I want to use both of proxy mocks and generated mocks in the single project. So I configured my sbt project to enable compiler plugin. generate-mocks and tests which use generated mocks were successful. However I got the following error for tests which use proxy mocks. They had been successful before configuring my sbt project for generated mocks.

[info]   java.lang.IllegalArgumentException: Unable to create proxy - possible classloader issue? Consider setting proxyClassLoaderStrategy
[info]   at org.scalamock.Proxy$.create(Proxy.scala:40)
[info]   at org.scalamock.ProxyMockFactory$class.mock(ProxyMockFactory.scala:30)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest.mock(ScalaProxyMockTest.scala:6)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply$mcV$sp(ScalaProxyMockTest.scala:14)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply(ScalaProxyMockTest.scala:12)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply(ScalaProxyMockTest.scala:12)
[info]   at org.scalatest.FunSuite$$anon$1.apply(FunSuite.scala:1265)
[info]   at org.scalatest.Suite$class.withFixture(Suite.scala:1968)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest.withFixture(ScalaProxyMockTest.scala:6)
[info]   at org.scalatest.FunSuite$class.invokeWithFixture$1(FunSuite.scala:1262)
[info]   ...
[info]   Cause: java.lang.IllegalArgumentException: interface org.scalamock.Mock is not visible from class loader
[info]   at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
[info]   at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
[info]   at org.scalamock.Proxy$.create(Proxy.scala:37)
[info]   at org.scalamock.ProxyMockFactory$class.mock(ProxyMockFactory.scala:30)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest.mock(ScalaProxyMockTest.scala:6)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply$mcV$sp(ScalaProxyMockTest.scala:14)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply(ScalaProxyMockTest.scala:12)
[info]   at jp.sf.amateras.scala.test.scalamock.ScalaProxyMockTest$$anonfun$1.apply(ScalaProxyMockTest.scala:12)
[info]   at org.scalatest.FunSuite$$anon$1.apply(FunSuite.scala:1265)
[info]   at org.scalatest.Suite$class.withFixture(Suite.scala:1968)
[info]   ...

Here is my sbt project configuration:

import sbt._
import Keys._
import ScalaMockPlugin._

object MyProject extends Build {

  override lazy val settings = super.settings ++ Seq(
    organization := "jp.sf.amateras.scala",
    version := "1.0",
    scalaVersion := "2.9.1",
    libraryDependencies += "org.scalamock" %% "scalamock-scalatest-support" % "2.2",
    autoCompilerPlugins := true,
    addCompilerPlugin("org.scalamock" %% "scalamock-compiler-plugin" % "2.2")
  )

  lazy val myproject = Project("MyProject", file(".")) settings(generateMocksSettings: _*) configs(Mock)

}

When I rolled back my project configuration (which has only library dependency to scalamock-scalatest-support), tests which use proxy mocks is successful.

Is it possible to use proxy mocks and generated mocks in the single project?

@paulbutcher
Copy link
Owner

Sincere apologies @takezoe. I found and fixed this bug a while ago, but haven't yet released a version of ScalaMock that includes the fix :-(

This is the commit that fixes the problem:

dc3595c

You should be able to work around it by using 2.3-SNAPSHOT. I'll try to get an official 2.3 release out this weekend.

Apologies once again.

@takezoe
Copy link
Author

takezoe commented May 14, 2012

No problem. I'm looking forward to 2.3 :-)

@paulbutcher
Copy link
Owner

I've just released 2.3 - let me know if you still have problems

@takezoe
Copy link
Author

takezoe commented May 19, 2012

Great! My all tests succeeded with ScalaMock 2.3 :-)
In addition, we are starting to move Scala 2.9.2 from 2.9.1. Do you have a plan that releases Scala 2.9.2 build?

@paulbutcher
Copy link
Owner

The 2.3 release already includes support for Scala 2.9.2 - let me know if you experience any problems with this.

@takezoe
Copy link
Author

takezoe commented May 19, 2012

Oh sorry, it worked with Scala 2.9.2 with no problem. Thanks for your work!

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