aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2018-01-29 14:18:56 +0100
committeradamw <adam@warski.org>2018-01-29 14:18:56 +0100
commit10620d432ff20d1bfed7cf184d8042acf95eb9d7 (patch)
treeece446a63aed2c5870f645e9ff7c54df3ab4e15b /core
parent88a3a820c8233d335242e51936bc22723c391cd3 (diff)
downloadsttp-10620d432ff20d1bfed7cf184d8042acf95eb9d7.tar.gz
sttp-10620d432ff20d1bfed7cf184d8042acf95eb9d7.tar.bz2
sttp-10620d432ff20d1bfed7cf184d8042acf95eb9d7.zip
Renaming the new stub method
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala9
-rw-r--r--core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala6
2 files changed, 6 insertions, 9 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala b/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
index a603894..2206a8f 100644
--- a/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
+++ b/core/src/main/scala/com/softwaremill/sttp/testing/SttpBackendStub.scala
@@ -66,8 +66,8 @@ class SttpBackendStub[R[_], S] private (
override def send[T](request: Request[T, S]): R[Response[T]] = {
Try(matchers.lift(request)) match {
- case Success(Some(responseMonad)) =>
- tryAdjustResponseType(rm, request.response, wrapResponse(responseMonad))
+ case Success(Some(response)) =>
+ tryAdjustResponseType(rm, request.response, response.asInstanceOf[R[Response[T]]])
case Success(None) =>
fallback match {
case None =>
@@ -86,9 +86,6 @@ class SttpBackendStub[R[_], S] private (
private def wrapResponse[T](r: Response[_]): R[Response[T]] =
rm.unit(r.asInstanceOf[Response[T]])
- private def wrapResponse[T](r: R[Response[_]]): R[Response[T]] =
- rm.map(r)(_.asInstanceOf[Response[T]])
-
override def close(): Unit = {}
override def responseMonad: MonadError[R] = rm
@@ -113,7 +110,7 @@ class SttpBackendStub[R[_], S] private (
}
new SttpBackendStub(rm, matchers.orElse(m), fallback)
}
- def thenRespondWithMonad(resp: => R[Response[_]]): SttpBackendStub[R, S] = {
+ def thenRespondWrapped(resp: => R[Response[_]]): SttpBackendStub[R, S] = {
val m: PartialFunction[Request[_, _], R[Response[_]]] = {
case r if p(r) => resp
}
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 8a4eeb2..92c62f7 100644
--- a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
+++ b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala
@@ -3,11 +3,11 @@ package com.softwaremill.sttp.testing
import java.io.ByteArrayInputStream
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}
+import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures {
@@ -29,7 +29,7 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures {
Response(Right("Ada"), 200, "OK", Nil, Nil)
})
.whenRequestMatches(_.uri.port.exists(_ == 8080))
- .thenRespondWithMonad(Response(Right("OK from monad"), 200, "OK", Nil, Nil))
+ .thenRespondWrapped(Response(Right("OK from monad"), 200, "OK", Nil, Nil))
"backend stub" should "use the first rule if it matches" in {
implicit val b = testingStub
@@ -172,7 +172,7 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures {
val before = System.currentTimeMillis()
implicit val s = SttpBackendStub(new FutureMonad()).whenAnyRequest
- .thenRespondWithMonad(Future {
+ .thenRespondWrapped(Future {
Thread.sleep(LongTimeMillis)
Response(Right("OK"), 200, "", Nil, Nil)
})