Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification count of stubbed method on spy is wrong for some method implementations #504

Open
johanhaleby opened this issue Jul 25, 2015 · 4 comments

Comments

Projects
None yet
3 participants
@johanhaleby
Copy link
Collaborator

commented Jul 25, 2015

What steps will reproduce the problem? 1. Run TimesExampleTest, see 'testSpy_Bad'. What is the expected output? What do you see instead? Expected a passing test, but fails with 3 invocations, instead of 2. What version of the product are you using? On what operating system? junit:junit:4.11
org.mockito:mockito-core:1.9.5
org.powermock:powermock-module-junit4:1.5.4
org.powermock:powermock-api-mockito:1.5.4 Please provide any additional information below. The TimesExample and TimesExample2 classes are the same, except TimesExample2 calls a private method instead.

If you comment out the @PrepareForTest line, and just use Mockito, both test methods will now pass.

Code example on gist

@ryan-gustafson

This comment has been minimized.

Copy link

commented Mar 7, 2016

Did the attachments for this come over when migrating from google code? The link seems to dump me back into google code...

I'm going through an upgrade from 1.5.4. to 1.6.4 and verification counts on spys appears to have even more issues than before. I was going to try to update the attached test cases.

@thekingnothing

This comment has been minimized.

Copy link
Member

commented Mar 8, 2016

@ryan-gustafson,
I've re-uploaded your example from google storage to gist (all google code downloads could find by links like https://storage.googleapis.com/google-code-attachments/powermock/issue-484/comment-0/TimesExampleTest.java ) . Please, verify them.

@thekingnothing thekingnothing added this to the Backlog milestone Mar 8, 2016

@thekingnothing thekingnothing self-assigned this Mar 8, 2016

@thekingnothing thekingnothing modified the milestones: Backlog, PowerMock 1.6.6 Apr 29, 2016

@thekingnothing

This comment has been minimized.

Copy link
Member

commented Jul 24, 2016

Main cause of the issue in how Mockito registers invocations. I've created an issue for Mockito. After issue will be fixed for Mockito 2 I'll add fix for Mockito 1.

@thekingnothing thekingnothing modified the milestones: Backlog, PowerMock 1.6.6 Jul 24, 2016

@thekingnothing

This comment has been minimized.

Copy link
Member

commented Jul 24, 2016

As workaround doReturn().when(mockObject).methodCall() could use instead `when(mockObject.methodCall()).thenReturn.

@thekingnothing thekingnothing removed this from the Backlog milestone Nov 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.