title: How do I create mock if my trait uses self-type restriction?
body: <p>I'm trying to use cake pattern and mocking. After reading bunch of blog-posts with tons of fashionable terms I can't make it working :(</p>
  
  <p>I'm using Spray and have following http service</p>
  
  <pre><code>trait ApiServiceAbstract extends HttpService with SprayJsonSupport {
    this : AppProvider =&gt;
  // tons of routes here
  }
  </code></pre>
  
  <p>where <code>AppProvider</code> is</p>
  
  <pre><code>trait AppProvider {
    val api : ApiManager
  }
  </code></pre>
  
  <p>For real server I combine it like this</p>
  
  <pre><code>class ApiServiceActor extends Actor with ApiServiceAbstract with RealApiManager {
  }
  </code></pre>
  
  <p>where <code>RealApiManager</code> extends <code>AppProvider</code>.</p>
  
  <p>Also <code>ApiManager</code> must be mixed in with <code>DbProvider</code> which looks like this</p>
  
  <pre><code>trait ApiManager {
    this : DbProvider =&gt;
  }
  
  trait RealDbProvider extends DbProvider {
    override lazy val dbManager = new DBManager
  }
  </code></pre>
  
  <p>In my unit-test I only want to test http portion and have mocked <code>ApiManager</code> which simply checks that object passed by the client is correct one.</p>
  
  <p>I cannot do this</p>
  
  <pre><code>override lazy val api = mock[ApiManager]
  </code></pre>
  
  <p>because <code>ApiManager</code> has to be mixed in with <code>DbProvider</code>. How can I fix this ? I see two options right now:</p>
  
  <ul>
  <li>Switch to mocking library that can instantiate classes with constructors with parameters (e.g. Mockito)</li>
  <li>Add <code>init(db : DBManager)</code> method and have <code>var</code> in <code>ApiManager</code> which is ugly</li>
  </ul>