Permalink
Browse files

Fix mocks that return mocks. Fixes #9.

  • Loading branch information...
1 parent bf7742e commit 6d926ea1a555458f59f3c39d7dac939cd137475c @paulbutcher committed Nov 3, 2011
Showing with 17 additions and 0 deletions.
  1. +1 −0 core/src/main/scala/ProxyMockFactory.scala
  2. +16 −0 core_tests/src/test/scala/ProxyMockTest.scala
@@ -33,6 +33,7 @@ trait ProxyMockFactory { self: AbstractMockFactory =>
name match {
case 'expects => addExpectation(proxy, args(0).asInstanceOf[Symbol])
case 'stubs => addExpectation(proxy, args(0).asInstanceOf[Symbol]).anyNumberOfTimes
+ case 'toString => "proxy mock object "+ System.identityHashCode(proxy)
case _ => methodsFor(proxy)(name)(args).asInstanceOf[AnyRef]
}
} catch {
@@ -114,4 +114,20 @@ class ProxyMockTest extends Suite with MockFactory {
m.setPosition(3.14159, 3.14159)
intercept[ExpectationException] { m.setPosition(1.0, 2.0) }
}
+
+ def testMockReturningMock {
+ trait Parent {
+ def getChild: Child
+ }
+ trait Child
+
+ val p = mock[Parent]
+ val c = mock[Child]
+
+ p expects 'getChild returning c
+
+ expect(c) { p.getChild }
+
+ verifyExpectations
+ }
}

0 comments on commit 6d926ea

Please sign in to comment.