Permalink
Browse files

Start compiling the examples again, and fix a bug that stopped proxy …

…mocks and generated mocks from co-existing
  • Loading branch information...
1 parent 3a3bc7c commit dc3595c0fba8bbb9724757cc5f4f6f281d5018bb @paulbutcher committed Jan 9, 2012
@@ -24,6 +24,14 @@ trait ClassLoaderStrategy {
def getClassLoader(interfaces: Class[_]*): ClassLoader
}
+object ClassLoaderStrategy {
+ var default: ClassLoaderStrategy = threadContextClassLoaderStrategy
+}
+
object threadContextClassLoaderStrategy extends ClassLoaderStrategy {
def getClassLoader(interfaces: Class[_]*) = Thread.currentThread.getContextClassLoader
+}
+
+object classClassLoaderStrategy extends ClassLoaderStrategy {
+ def getClassLoader(interfaces: Class[_]*) = interfaces.head.getClassLoader
}
@@ -24,10 +24,10 @@ import scala.collection.mutable.{ListBuffer, Map}
trait ProxyMockFactory { self: MockFactoryBase =>
- protected var proxyClassLoaderStrategy = threadContextClassLoaderStrategy
+ protected def getClassLoaderStrategy = ClassLoaderStrategy.default
protected def mock[T: ClassManifest] = {
- val proxy = Proxy.create(proxyClassLoaderStrategy, classOf[Mock], classManifest[T].erasure) {
+ val proxy = Proxy.create(getClassLoaderStrategy, classOf[Mock], classManifest[T].erasure) {
(proxy: AnyRef, name: Symbol, args: Array[AnyRef]) =>
try {
name match {
@@ -20,7 +20,7 @@
package org.scalamock.scalatest
-import org.scalamock.{MockFactoryBase, MockingURLClassLoader}
+import org.scalamock.{ClassLoaderStrategy, classClassLoaderStrategy, MockFactoryBase, MockingURLClassLoader}
import org.scalatest.{AbstractSuite, Distributor, Filter, Reporter, Stopper, Suite, Tracker}
import java.net.URL
@@ -50,6 +50,9 @@ trait MockFactory extends AbstractSuite with MockFactoryBase { this: Suite =>
def runInternal(testName: Option[String], reporter: Reporter, stopper: Stopper, filter: Filter,
configMap: Map[String, Any], distributor: Option[Distributor], tracker: Tracker) {
+ if (configMap contains "mock.classes")
+ ClassLoaderStrategy.default = classClassLoaderStrategy
+
super.runTests(testName, reporter, stopper, filter, configMap, distributor, tracker)
}

0 comments on commit dc3595c

Please sign in to comment.