title: ScalaMock. Mock a class that takes arguments
body: <p>Full disclosure: I'm very new to mocking and mocking frameworks. I'm trying to use ScalaMock because it seemed like the 'default' mocking framework to use with ScalaTest but I am happy to use any other framework which is compatible with ScalaTest.</p>
  
  <p>The problem: I've written in Scala a class that talks to a socket. The class has a type parameter of what sort of socket it is to talk to and one of it's arguments is a factory for creating sockets of that type. It has the signature:</p>
  
  <pre><code>class XScanner[T &lt;: SocketClient](
    confPath: String = "/etc/default/configPath",
    socketClientFactory: String =&gt; T
  ) extends ScannerBase(path)
  </code></pre>
  
  <p>I would like to be able to write unit tests for this class by supplying a mock SocketClient so my test code doesn't have to connect to a real socket but I can't work out how to do this with ScalaMock.</p>
  
  <p>My test code looks like this:</p>
  
  <pre><code>val t = new XScanner[SocketClient](confPath, (s: String) =&gt; mock[SocketClient])
  </code></pre>
  
  <p>Clearly that won't compile because <code>SocketClient</code> expects a path to the socket as an argument but I can't call <code>mock[SocketClient(s)]</code> because that's not a type and I can't call <code>mock[SocketClient](s)</code> because mock doesn't take the arguments of the type passed to it as it's own arguments. </p>
  
  <p>So how can I write a mock <code>SocketClient</code> factory to pass to my Scanner? I can't even work out how to mock a class that takes arguments!</p>