diff options
author | phaller <hallerp@gmail.com> | 2012-11-26 18:37:20 +0100 |
---|---|---|
committer | phaller <hallerp@gmail.com> | 2012-11-26 23:27:29 +0100 |
commit | 4eb47ba34bf10bc483fa8f04a9f76708f9161317 (patch) | |
tree | 275eddcf4ab55fb04e9c5224c6c1da69de6c0449 /src | |
parent | 9ea2cc44e98c110843780aef09c7d1a695458be3 (diff) | |
download | scala-async-4eb47ba34bf10bc483fa8f04a9f76708f9161317.tar.gz scala-async-4eb47ba34bf10bc483fa8f04a9f76708f9161317.tar.bz2 scala-async-4eb47ba34bf10bc483fa8f04a9f76708f9161317.zip |
More tests for ExceptionsSpec
Diffstat (limited to 'src')
-rw-r--r-- | src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala index 6f9e4ec..733ea01 100644 --- a/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala +++ b/src/test/scala/scala/async/run/exceptions/ExceptionsSpec.scala @@ -21,19 +21,41 @@ import org.junit.runners.JUnit4 class ExceptionsSpec { @Test - def `complete future with exception`() { - val future0 = future[Any] { - "five!".length + def `uncaught exception within async`() { + val fut = async { throw new Exception("problem") } + intercept[Exception] { Await.result(fut, 2.seconds) } + } + + @Test + def `uncaught exception within async after await`() { + val base = future { "five!".length } + val fut = async { + val len = await(base) + throw new Exception(s"illegal length: $len") + } + intercept[Exception] { Await.result(fut, 2.seconds) } + } + + @Test + def `await failing future within async`() { + val base = future[Int] { throw new Exception("problem") } + val fut = async { + val x = await(base) + x * 2 } + intercept[Exception] { Await.result(fut, 2.seconds) } + } - val future2 = async { - val a = await(future0.mapTo[Int]) // result: 5 - val b = await((future { (a * 2).toString }).mapTo[Int]) // result: 10 + @Test + def `await failing future within async after await`() { + val base = future[Any] { "five!".length } + val fut = async { + val a = await(base.mapTo[Int]) // result: 5 + val b = await((future { (a * 2).toString }).mapTo[Int]) // result: ClassCastException val c = await(future { (7 * 2).toString }) // result: "14" b + "-" + c } - - intercept[ClassCastException] { Await.result(future2, 5.seconds) } + intercept[ClassCastException] { Await.result(fut, 2.seconds) } } } |