perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.64k stars 1.56k forks source link

testing: spark request/response is hard to be mocked #960

Open qnislavnachev opened 6 years ago

qnislavnachev commented 6 years ago

As now spark have RequestResponseFactory.create(HttpServletRequest), but this is a way harder for testing. It will be more easily if Request and Response are just interfaces and they will be mocked easily. For now to mock the request.body() method I should implement ServletInputStream and to mock HttpServletRequest.inputStream .... that looks by this way:
1

and then

2

for now I have 3 expectations instead of having just one like this:

oneOf(request).body()
will(returnValue("my body is here"))
qnislavnachev commented 6 years ago

Also I cannot find a way to mock request.params("some param")