Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The insight is that what you need to mock is <code>socketClientFactory</code>. And then set it up to return a mock <code>SocketClient</code>.</p> <p>Given:</p> <pre><code>trait SocketClient { def frobnicate(): Unit } class ScannerBase(path: String) class XScanner[T &lt;: SocketClient]( confPath: String = "/etc/default/configPath", socketClientFactory: String =&gt; T ) extends ScannerBase(confPath) { val socket = socketClientFactory("Some Socket Name") socket.frobnicate } </code></pre> <p>(side note - your default value for <code>confPath</code> can never be used because there's no default value for <code>socketClientFactory</code>).</p> <p>then this should get you started (this is with Scala 2.9.x and ScalaMock2 - 2.10.x with ScalaMock3 will be slightly different, but not much so):</p> <pre><code>import org.scalatest.FunSuite import org.scalamock.scalatest.MockFactory import org.scalamock.generated.GeneratedMockFactory class ScannerTest extends FunSuite with MockFactory with GeneratedMockFactory { test("scanner") { val mockFactory = mockFunction[String, SocketClient] val mockClient = mock[SocketClient] mockFactory.expects("Some Socket Name").returning(mockClient) mockClient.expects.frobnicate val scanner = new XScanner("path/to/config", mockFactory) } } </code></pre> <p>For completeness, here's the same test in Scala 2.10.0 and ScalaMock3:</p> <pre><code>import org.scalatest.FunSuite import org.scalamock.scalatest.MockFactory class ScannerTest extends FunSuite with MockFactory { test("scanner") { val mockFactory = mockFunction[String, SocketClient] val mockClient = mock[SocketClient] mockFactory.expects("Some Socket Name").returning(mockClient) (mockClient.frobnicate _).expects() val scanner = new XScanner("path/to/config", mockFactory) } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload