I was writing test for following code snippet, I am getting nullPointerException for StreamedResponse body. I am not able to mock StreamedResponse body.
I tried
mock[StreamedResponse].body returns Source[ByteString("")]
But getting Source.type doesn't take parameters error.
streamResponse map {
case StreamedResponse(response, body) =>
if (response.status == 200) {
val contentType = response.headers.get("Content-Type").flatMap(_.headOption).getOrElse("application/pdf")
response.headers.get("Content-Length") match {
case Some(Seq(length)) =>
Ok.sendEntity(HttpEntity.Streamed(body, Some(length.toLong), Some(contentType)))
case _ =>
Ok.chunked(body).as(contentType)
}
} else {
Redirect(pdfService.buildEspacenetLink(ucid))
}
}
This is code where I used StreamResponse.
I want to test case _ => Ok.chunked(body).as(contentType) this part of code with some data as response body.