title: [Scala][Mokito] How to stub a Future function to throw exception
body: <p>I m writing test case for stubbing a repository <code>Future</code> function throws an <code>Exception</code> to simulate some DB error.  </p>
  
  <p>I expect the DB exception throw by Repository.create and it will be handled by Actor <code>.recover{}</code>. But it throws an exception and cannot be caught by <code>.recover</code></p>
  
  <pre><code>// test 
  it should "return NOT created message if exception thrown" in {
      val repository = mock[Repository]
      val service = TestActorRef(props(repository))
      implicit val ec: ExecutionContext = service.dispatcher
      val mockTeam = mock[Team]
  
      when(repository.create(any[Team])(same(ec))).thenReturn(Future.failed(throw new Exception))
      service ! CreateTeam(mockTeam)
      expectMsg(TeamNotCreated())
  }
  
  
  // service == actor
  override def receive = {
      case CreateTeam(team) =&gt; createTeam(team)
      .recover {
        case error: Exception =&gt; TeamNotCreated()
      }.pipeTo(sender())
  }
  private def createTeam(team: Team)
    : Future[TeamCreateEvent] = {
          for {
            newTeam &lt;- repository.create(team = team)
          } yield {
            if (newTeam isDefined) TeamCreated(newTeam)
            else TeamNotCreated()
          }
        }
  
  // repository
  override def create(team: TeamEntity)(implicit ec: ExecutionContext)
    : Future[Option[TeamEntity]] = {
      Future {
        val column = Team.column
        /****  I want to simulate some exception was thrown here ***/
        val newId = Team.createWithNamedValues(
          column.name -&gt; team.name
        )
        if (newId.isValidLong) Option(team.copy(id = newId)) else None
      }
    }
  </code></pre>
  
  <p><strong>Here is the output:</strong></p>
  
  <pre><code>[info] - should return NOT created message if exception thrown *** FAILED ***
  [info]   java.lang.Exception:
   should return updated message if collaborator team create success *** FAILED ***
  [info]   org.mockito.exceptions.misusing.UnfinishedStubbingException: 
  
  Unfinished stubbing detected here:
  .g. thenReturn() may be missing.
  [info] Examples of correct stubbing:
  [info]     when(mock.isOk()).thenReturn(true);
  [info]     when(mock.isOk()).thenThrow(exception);
  [info]     doThrow(exception).when(mock).someVoidMethod();
  [info] Hints:
  [info]  1. missing thenReturn()
  [info]  2. you are trying to stub a final method, you naughty developer!
  [info]  3: you are stubbing the behaviour of another mock inside before 'thenReturn' instruction if completed
  </code></pre>
  
  <p>I had tried to to replace <code>thenReturn(Future.failed..</code> with <code>thenThrow(new Exception)</code> but not working with error <code>ava.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg while waiting for</code></p>