You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Injected @Mocked object SelfReturningClass@1d251891
AnotherInstance SelfReturningClass@7c30a502
ignoredReturnValue1 SelfReturningClass@1d251891
mockit.internal.UnexpectedInvocation: Unexpected invocation of:
SelfReturningClass#doSmthAndReturnSelf(int)
with arguments: 2
on instance: SelfReturningClass@7c30a502
when was expecting an invocation of:
SelfReturningClass#doSmthAndReturnSelf(int)
with arguments: 2
on mock instance: SelfReturningClass@1d251891
at SelfReturningClass.doSmthAndReturnSelf(SelfReturningClass.java)
at TestCascade.testFailed(TestCascade.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: Missing invocation
at SelfReturningClass.doSmthAndReturnSelf(SelfReturningClass.java)
at TestCascade$1.<init>(TestCascade.java:17)
at TestCascade.testFailed(TestCascade.java:15)
... 8 more
First invocation is successful.
For second invocation I get "Unexpected invocation" .
Method signature matches exactly. Instances are different - but i am using @mocked injection type, so i must mock all instances of this class.
I captured returned value to variable ‘ignoredReturnValue1’, for debugging proposes in this test, because i thought there are issue with cascade mocking. But every thing seems fine: returned value equals to «Injected @mocked object».
But in production test code i really ignore returning value. That’s why i do not specify any return value in this expectation originally.
So do i miss something in this combination: @mocked + several invocations in StrictExpectations + self returning objects?
Should i always use result statement in expectation block when method is non void , or i can omit result?
Is it a bug behaviour of JMockit?
I have attached working example, so you can reproduce issue. (tried on jdk 1.8 and 1.7)
Hello.
I have noticed strange issues while mocking classes which returns self as method result value (like builder). Here is an example:
Running this test gives me :
First invocation is successful.
For second invocation I get "Unexpected invocation" .
Method signature matches exactly. Instances are different - but i am using @mocked injection type, so i must mock all instances of this class.
I captured returned value to variable ‘ignoredReturnValue1’, for debugging proposes in this test, because i thought there are issue with cascade mocking. But every thing seems fine: returned value equals to «Injected @mocked object».
I found workaround how to get test working :
When i explicitly return mocked object as result then subsequent invocation works fine:
But in production test code i really ignore returning value. That’s why i do not specify any return value in this expectation originally.
So do i miss something in this combination:
@mocked + several invocations in StrictExpectations + self returning objects?
Should i always use result statement in expectation block when method is non void , or i can omit result?
Is it a bug behaviour of JMockit?
I have attached working example, so you can reproduce issue. (tried on jdk 1.8 and 1.7)
jmockit_cascade_issue.zip
The text was updated successfully, but these errors were encountered: