Skip to content

Instantly share code, notes, and snippets.

@maowug
Created November 11, 2016 09:59
Show Gist options
  • Save maowug/b0e3f564fc9c6290f3367a6650d194d2 to your computer and use it in GitHub Desktop.
Save maowug/b0e3f564fc9c6290f3367a6650d194d2 to your computer and use it in GitHub Desktop.
futureValue fails? with intercept

try

intercept[DBException] {
  categoryDAO.insert(catFixture).futureValue
  categoryDAO.insert(catFixture).futureValue
}

firstly, futureValue converted from future returned from categoryDAO.insert

implicit def convertScalaFuture[T](scalaFuture: scala.concurrent.Future[T]): FutureConcept[T] =
    new FutureConcept[T] {
      def eitherValue: Option[Either[Throwable, T]] =
         scalaFuture.value.map {
           case Success(o) => Right(o)
           case Failure(e) => Left(e)
         }

then, in futureValue

 case Some(Left(e)) =>
            throw new TestFailedException(
              sde => Some {
                if (e.getMessage == null)
                  Resources("futureReturnedAnException", e.getClass.getName)
                else
                  Resources("futureReturnedAnExceptionWithMessage", e.getClass.getName, e.getMessage)
              },
              Some(e),
              getStackDepthFun("Futures.scala", methodName, adjustment)
            )
            

always throw TestFailedException & TestFailedException's fields are not awailable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment