1

Here is the few lines of code I would like to unit test for different http response codes. One of them is code 201 . Please advise

val cb = ClientBuilder()
val myClient = cb.build()
val req =
      RequestBuilder()
        .url(loginUrl)
        .setHeader("Content-Type", "application/json")
        .buildPost(copiedBuffer(body.getBytes(UTF_8)))

myClient(req).map(http.Response(_)).flatMap { response =>
      response.statusCode match {
        case 201 => //parse response
        case _ =>
          println(" some reseponse")
          Future(proxy(response))
       }
}
RajKon
  • 420
  • 1
  • 8
  • 20
  • If you encapsulate the `201` logic into a method, at least you could trivially verify it through a unittest – dm03514 Jun 10 '16 at 00:18
  • @dm03514 I am sure it could be done something along these lines but could not get it to work . ` val request = Request() val service = mock[Service[http.Request, http.Response]] stub(service(any[http.Request])).toReturn(Future.value(Response(request.version, http.Status.Created))) stub(service.close()).toReturn(Future.Done)` – RajKon Jun 13 '16 at 21:40

0 Answers0