Browse files

Add proxy mock-based test

  • Loading branch information...
1 parent ed77f7a commit 7d80734b4a5c1958b13698e49f88a796980ca458 @paulbutcher committed Jan 11, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/test/scala/com/example/ControllerProxyTest.scala
View
30 src/test/scala/com/example/ControllerProxyTest.scala
@@ -0,0 +1,30 @@
+package com.example
+
+import org.scalatest.FunSuite
+import org.scalamock.ProxyMockFactory
+import org.scalamock.scalatest.MockFactory
+import scala.math.{Pi, sqrt}
+
+class ControllerProxyTest extends FunSuite with MockFactory with ProxyMockFactory {
+
+ test("draw line") {
+ val mockTurtle = mock[Turtle]
+ val controller = new Controller(mockTurtle)
+
+ inSequence {
+ inAnyOrder {
+ mockTurtle expects 'penUp
+ mockTurtle expects 'getPosition returning (0.0, 0.0)
+ mockTurtle expects 'getAngle returning 0.0
+ }
+ mockTurtle expects 'turn withArgs(~(Pi / 4))
+ mockTurtle expects 'forward withArgs(~sqrt(2.0))
+ mockTurtle expects 'getAngle returning Pi / 4
+ mockTurtle expects 'turn withArgs(~(-Pi / 4))
+ mockTurtle expects 'penDown
+ mockTurtle expects 'forward withArgs(1.0)
+ }
+
+ controller.drawLine((1.0, 1.0), (2.0, 1.0))
+ }
+}

0 comments on commit 7d80734

Please sign in to comment.