How to claim that a mocking method is never called using ScalaTest and ScalaMock?

I am using ScalaTest 2.0 and ScalaMock 3.0.1. How can I argue that the method of scoffing is never called?

import org.scalatest._
import org.scalamock._
import org.scalamock.scalatest.MockFactory

class TestSpec extends FlatSpec with MockFactory with Matchers {

  "..." should "do nothing if getting empty array" in {
    val buyStrategy = mock[buystrategy.BuyStrategyTrait]
    buyStrategy expects 'buy never
    // ...
  }
}
+4
source share
1 answer

There are two styles of using ScalaMock; I will show you a solution showing the recording style based on Mockito Record-Then-Verify. Say you had a trait Fooas follows:

trait Foo{
  def bar(s:String):String
}

And then a class that uses an instance of this trait:

class FooController(foo:Foo){  
  def doFoo(s:String, b:Boolean) = {
    if (b) foo.bar(s)
  }
}

If I wanted to check that if a false value is given for a parameter b, foo.barit is not called, I could set it like this:

val foo = stub[Foo]
val controller = new FooController(foo)
controller.doFoo("hello", false)
(foo.bar _).verify(*).never 

*, , bar String. , , :

(foo.bar _).verify("hello").never 
+4

All Articles