Closed hamid-nazari closed 8 years ago
Lambda bodies are implemented differently from anything else in the JVM. For now, they are not supported.
Out of curiosity, is there a real-world use for this? What kind of test would need to mock a lambda?
This test code snippet has nothing to do with the actual code I encountered this issue with. In that scenario we have a set of dependencies (like hooks) defined as functional interfaces and of course implemented as lambdas and I use JMockit to verify and track my code proper interaction with those hooks. Specifically, I want to verify these hooks invocation count for specific set of input arguments from within my code which is pretty much complex and distributed. I suppose such use-cases justify this requirement according to the behavioral testing paradigm.
Hi, I've come across this issue which seem naive and simple to solve, but has become a pain for my tests. When I try to partially mock an inline implementation of any form of interface, especially those Functional Interfaces introduced with Java8, using Lambda expression I get an annoying
java.lang.VerifyError
like this:To my surprise, the same implementation using anonymous inline class gets partially mocked successfully. For my further amusement, I found that the Lambda body seems to play a role here; that is, using a local variable or a class filed in the same Lambda body has different effects for partial mocking. This is the test case to demonstrate this issue:
The test fails with the error I mentioned earlier at the line I've commented. I check this with both versions JMockit 1.16 and JMockit 1.19.
My environment: