title: How to mock a function that returns a value class instance with Mockito?
body: <p>I'm trying to mock a method that returns an instance of a value class (<code>extends AnyVal</code>)
  I'm getting some weird error message, which I understand (because of value class erasure) but I'm surprised Mockito doesn't cope with that.</p>
  
  <p>My class:</p>
  
  <pre><code>case class MyValueClass(value: String) extends AnyVal
  </code></pre>
  
  <p>The function I want to mock:</p>
  
  <pre><code>trait ToMock {
    def something(someParams: String): MyValueClass
  }
  </code></pre>
  
  <p>And the mock:</p>
  
  <pre><code>val theMock = mock[ToMock]
  val returned = MyValueClass("test")
  when(theMock.something("test")).thenReturn(returned)
  </code></pre>
  
  <p>This code generates the following error:</p>
  
  <pre><code>MyValueClass cannot be returned by something()
  something() should return String
  </code></pre>
  
  <p>But of course, if I make it return a String, it doesn't compile anymore...</p>
  
  <p>If I remove <code>extends AnyVal</code>, of course it works fine.</p>