Skip to content

Instantly share code, notes, and snippets.

@Chandler
Created July 31, 2014 21:02
Show Gist options
  • Save Chandler/8650a3ad05e79495a317 to your computer and use it in GitHub Desktop.
Save Chandler/8650a3ad05e79495a317 to your computer and use it in GitHub Desktop.
case class MyException(errorCode: Int) extends RuntimeException
def onThrow[T <: Throwable](check: Check[T])(implicit m: Manifest[T]): Check[Try[_]] =
expected("A Throw(e: %s)".format(m.erasure)).exceptWhen { case Throw(NonFatal(e: T)) => check(e) }
val check = onThrow {
hasType[Unauthorized.type].on { e: ClientError => e.errorCause }
}
check(Throw(MyException(5)))
res3: com.twitter.coreservices.integration.TestResult = TestResult(HierarchicalLog(List(Value(Entry(2014-07-31 21:02:22 +0000,
Error(java.lang.ClassCastException: MyException cannot be cast to com.twitter.servo.exception.thriftscala.ClientError))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment