aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala/com
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-11-13 13:40:11 +0100
committeradamw <adam@warski.org>2017-11-13 13:40:11 +0100
commit927c7c73b9766e825e1949667219ee367f342054 (patch)
tree4ae371ee30f40395b4f0cf721b816c2f01a7e07b /core/src/test/scala/com
parent9635a25aeead9d56e9f8b34518df19746e81967d (diff)
downloadsttp-927c7c73b9766e825e1949667219ee367f342054.tar.gz
sttp-927c7c73b9766e825e1949667219ee367f342054.tar.bz2
sttp-927c7c73b9766e825e1949667219ee367f342054.zip
#43: supporting exceptions in the stub backend
Diffstat (limited to 'core/src/test/scala/com')
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
index 9e10cd7..292d324 100644
--- a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
@@ -1,5 +1,9 @@
package com.softwaremill.sttp.testing
+import java.util.concurrent.TimeoutException
+
+import scala.concurrent.ExecutionContext.Implicits.global
+
import com.softwaremill.sttp._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{FlatSpec, Matchers}
@@ -70,6 +74,25 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures {
ada.body should be(Right("Ada"))
}
+ it should "handle exceptions thrown instead of a response (synchronous)" in {
+ implicit val s = SttpBackendStub(HttpURLConnectionBackend())
+ .whenRequestMatches(_ => true)
+ .thenRespond(throw new TimeoutException())
+
+ a[TimeoutException] should be thrownBy {
+ sttp.get(uri"http://example.org").send()
+ }
+ }
+
+ it should "handle exceptions thrown instead of a response (asynchronous)" in {
+ implicit val s = SttpBackendStub(new FutureMonad())
+ .whenRequestMatches(_ => true)
+ .thenRespond(throw new TimeoutException())
+
+ val result = sttp.get(uri"http://example.org").send()
+ result.failed.futureValue shouldBe a[TimeoutException]
+ }
+
val testingStubWithFallback = SttpBackendStub
.withFallback(testingStub)
.whenRequestMatches(_.uri.path.startsWith(List("c")))