summaryrefslogtreecommitdiff
path: root/test/files/jvm/future-spec/PromiseTests.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-02-24 17:22:22 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-02-24 17:22:22 -0800
commit092690e7bf71bb22e6e57afb7ea7f67fdfe31a0a (patch)
tree8743138e4b8e46854908e1c38f7fee0bed550709 /test/files/jvm/future-spec/PromiseTests.scala
parentdff479907919f59f35c4efa75e46950d8a239b5b (diff)
parentce68a973834804113ece6e6e2aa39e9825576b97 (diff)
downloadscala-2.11.6.tar.gz
scala-2.11.6.tar.bz2
scala-2.11.6.zip
Merge pull request #4357 from retronym/merge/2.10.x-to-2.11.x-20150224v2.11.6
Merge 2.10.x to 2.11.x
Diffstat (limited to 'test/files/jvm/future-spec/PromiseTests.scala')
-rw-r--r--test/files/jvm/future-spec/PromiseTests.scala75
1 files changed, 67 insertions, 8 deletions
diff --git a/test/files/jvm/future-spec/PromiseTests.scala b/test/files/jvm/future-spec/PromiseTests.scala
index 12b9168c5d..67c8c542ba 100644
--- a/test/files/jvm/future-spec/PromiseTests.scala
+++ b/test/files/jvm/future-spec/PromiseTests.scala
@@ -44,20 +44,79 @@ class PromiseTests extends MinimalScalaTest {
}.getMessage mustBe ("br0ken")
}
+ "be completable with a completed Promise" in {
+ {
+ val p = Promise[String]()
+ p.tryCompleteWith(Promise[String]().success("foo").future)
+ Await.result(p.future, defaultTimeout) mustBe ("foo")
+ }
+ {
+ val p = Promise[String]()
+ p.completeWith(Promise[String]().success("foo").future)
+ Await.result(p.future, defaultTimeout) mustBe ("foo")
+ }
+ {
+ val p = Promise[String]()
+ p.tryCompleteWith(Promise[String]().failure(new RuntimeException("br0ken")).future)
+ intercept[RuntimeException] {
+ Await.result(p.future, defaultTimeout)
+ }.getMessage mustBe ("br0ken")
+ }
+ {
+ val p = Promise[String]()
+ p.tryCompleteWith(Promise[String]().failure(new RuntimeException("br0ken")).future)
+ intercept[RuntimeException] {
+ Await.result(p.future, defaultTimeout)
+ }.getMessage mustBe ("br0ken")
+ }
+ }
}
"A successful Promise" should {
- val result = "test value"
- val promise = Promise[String]().complete(Success(result))
- promise.isCompleted mustBe (true)
- futureWithResult(_(promise.future, result))
+ "be completed" in {
+ val result = "test value"
+ val promise = Promise[String]().complete(Success(result))
+ promise.isCompleted mustBe (true)
+ futureWithResult(_(promise.future, result))
+ }
+
+ "not be completable with a completed Promise" in {
+ {
+ val p = Promise.successful("bar")
+ p.tryCompleteWith(Promise[String]().success("foo").future)
+ Await.result(p.future, defaultTimeout) mustBe ("bar")
+ }
+ {
+ val p = Promise.successful("bar")
+ p.completeWith(Promise[String]().success("foo").future)
+ Await.result(p.future, defaultTimeout) mustBe ("bar")
+ }
+ }
}
"A failed Promise" should {
- val message = "Expected Exception"
- val promise = Promise[String]().complete(Failure(new RuntimeException(message)))
- promise.isCompleted mustBe (true)
- futureWithException[RuntimeException](_(promise.future, message))
+ "be completed" in {
+ val message = "Expected Exception"
+ val promise = Promise[String]().complete(Failure(new RuntimeException(message)))
+ promise.isCompleted mustBe (true)
+ futureWithException[RuntimeException](_(promise.future, message))
+ }
+ "not be completable with a completed Promise" in {
+ {
+ val p = Promise[String]().failure(new RuntimeException("unbr0ken"))
+ p.tryCompleteWith(Promise[String].failure(new Exception("br0ken")).future)
+ intercept[RuntimeException] {
+ Await.result(p.future, defaultTimeout)
+ }.getMessage mustBe ("unbr0ken")
+ }
+ {
+ val p = Promise[String]().failure(new RuntimeException("unbr0ken"))
+ p.completeWith(Promise[String]().failure(new Exception("br0ken")).future)
+ intercept[RuntimeException] {
+ Await.result(p.future, defaultTimeout)
+ }.getMessage mustBe ("unbr0ken")
+ }
+ }
}
"An interrupted Promise" should {