com-lihaoyi / utest

A simple testing framework for Scala

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] equivalence of recoverToSucceededIf

tiboun opened this issue · comments

Hi,

I would like to know the equivalence of recoverToSucceededIf in scalatest in µtest. I've currently done a workaround like this one :

import scala.concurrent.Future

trait UTestExt {
  def recoverToSucceededIf[T <: Throwable: Manifest](
      f: => Future[Any]): Future[Any] = {
    import scala.concurrent.ExecutionContext.Implicits.global
    f.map[Either[Throwable, Throwable]](_ => Left(new RuntimeException("no exception occured"))).recover {
      case e: T => Right(e)
      case e    => Left(e)
    } map (e => {
      assert(e.isRight,
        e.left.get.getClass.getName + " has been thrown instead of " + manifest[T].runtimeClass.getName)
    })
  }
}

Thanks.

Best regards

Questions go in the gitter channel, not the issue tracker