title: Scala testing with type enrichment
body: <p>I've become attached to type enrichment, for example</p>
  
  <pre><code>object MyImplicits{
    implicit class RichInt(i: Int){
      def complexCalculation: Int = i * 200 
    }
  }
  </code></pre>
  
  <p>Which I use in code like this</p>
  
  <pre><code>object Algorithm{
    def apply(rand: Random) = {
      import MyImplicits._
      rand.nextInt.complexCalculation + 1
    }
  }
  </code></pre>
  
  <p>But how I can isolate and unit test Algorithm now?  In particular, I'd like to mock the implemention of <code>complexCalculation</code>, something like this:</p>
  
  <pre><code>class MyAlgorithmTest extends FreeSpec with MockitoSugar{
    import org.mockito.Mockito.when
  
    "MyApgorithm" {
      "Delegates complex calculation" in {
        val mockRandom = mock[Random]
        when(mockRandom.nextInt()).thenReturn(1)
  
        // This wouldn't work, but is the kind of thing I'm looking for
        //when(1.complexCalculation).thenReturn(2)
        val expected = 1 * 2 + 1
  
        val result = MyAlgorithm(mockRandom)
        assert(result === expected)
      }
    }
  }
  </code></pre>