All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalamock.scalatest.AbstractAsyncMockFactory.scala Maven / Gradle / Ivy

package org.scalamock.scalatest

import org.scalatest._
import org.scalatest.exceptions.{StackDepthException, TestFailedException}

import scala.concurrent.Future
import scala.util.control.NonFatal

trait AbstractAsyncMockFactory extends AsyncTestSuiteMixin with AsyncMockFactoryBase { this: AsyncTestSuite =>

  type ExpectationException = TestFailedException

  abstract override def withFixture(test: NoArgAsyncTest): FutureOutcome = {
    if (autoVerify) {
      new FutureOutcome(withExpectations(super.withFixture(test).toFuture).recoverWith({
        case NonFatal(ex) => Future.successful(Exceptional(ex))
      }))
    } else {
      super.withFixture(test)
    }
  }

  protected def newExpectationException(message: String, methodName: Option[Symbol]) =
    new TestFailedException((_: StackDepthException) => Some(message), None, failedCodeStackDepthFn(methodName))

  protected var autoVerify = true

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy