HttpExt.singleRequest with implicit parameters can not be mocked
See original GitHub issueIf I try to mock the object HttpExt
(imported like this import akka.http.scaladsl.HttpExt
) it will not work with this library.
This one will mock the object
import akka.http.scaladsl.HttpExt
import org.scalatest.mockito.MockitoSugar.mock
...
val mockHttp = mock[HttpExt]
this one will not work i.e. it will just return an instance of HttpExt and not a mock
import akka.http.scaladsl.HttpExt
import org.mockito.MockitoSugar.mock
...
val mockHttp = mock[HttpExt]
I also could not spy an HttpExt instance.
I am using
"org.mockito" % "mockito-scala_2.12" % "1.0.1"
and
"org.scalatest" % "scalatest_2.12" % "3.0.5" % "test"
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Mock a method without arguments but with implicit parameters
The solution is: (m.getResult()(_: ExecutionContext)).expects(*) returning "...", if you update your answer I will accept it.
Read more >[Solved]-How to test client-side Akka HTTP-scala
singleRequest (_) def sampleTextFile(uri: Uri)( implicit akkaSystem: ActorSystem, ... Then in my test I can just provide a mock HttpResponder .
Read more >Implicit Parameters - Oracle Help Center
This chapter describes the implicit parameters used in REST service handlers that are not explicitly declared. Oracle REST Data Services (ORDS) adds these ......
Read more >How to verify mocked method call involving implicit arguments ...
Invalid use of argument matchers! 2 matchers expected, 1 recorded. This exception may occur if matchers are combined with raw values: //incorrect:
Read more >Implicit Parameters In Scala - GeeksforGeeks
In simpler terms, if no value or parameter is passed to a method or function, then the compiler will look for implicit value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gadcam It actually doesn’t For starters, Scalatest doesn’t provide any mocking library, it only wraps the
mock
method with a nicer syntax, but you are 100% using the Java Mockito. Java Mockito is completely oblivious to default arguments (and any other Scala-only feature), from the Mockito point of view, they are null if you don’t provide them (you can check this by writing averify
to see what arguments were passed to the method). You can find a more detailed explanation here@gadcam The problem is that mockito-scala is aware of default arguments, if you look at the signature of
singleRequest
it looks likeNow, the
log
parameter receives as defaultsystem.log
. Assystem
hasn’t been stubbed, mockito-scala will return a SmartNull (a mock that will fail if you call any method on it) which is the one that is throwing that exception you see…You have many ways to overcome this, but probably the easiest is to pass a mock of a
LoggingAdapter
to thesingleRequest
method so the default value is not used…BTW, your code would look much cleaner with the new API, e.g.