title: Is it possible to mock / override dependencies / imports in Scala?
body: <p>I have some code looking like this:</p>
  
  <pre><code>package org.samidarko.actors
  
  import org.samidarko.helpers.Lib
  
  class Monitoring extends Actor {
  
    override def receive: Receive = {
      case Tick =&gt;
         Lib.sendNotification()
      }
  }
  </code></pre>
  
  <p>Is there a way to <strong>mock/stub</strong> <code>Lib</code> from <strong>ScalaTest</strong> like with <a href="https://github.com/thlorenz/proxyquire" rel="nofollow noreferrer">proxyquire</a> for nodejs?</p>
  
  <p>I read that I could use dependency injection but I would rather not do that</p>
  
  <p>Is my only alternative is to pass my lib as class parameter?</p>
  
  <pre><code>class Monitoring(lib: Lib) extends Actor {
  </code></pre>
  
  <p>Any advice to make it more testable? Thanks</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p><a href="https://stackoverflow.com/users/9297144/xavier-guihot">Xavier Guihot</a>'s answer is an interesting approach of the problem but I choose to change the code for testing purpose.</p>
  
  <p>I'm passing the <code>Lib</code> as parameter and I'm mocking with <a href="http://site.mockito.org/" rel="nofollow noreferrer">mockito</a>, it makes the code easier to test and to maintain than shadowing the scope.</p>