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

@johanhaleby
Copy link
Collaborator

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
Copy link

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.

@thekingn0thing
Copy link
Member

@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.

@thekingn0thing
Copy link
Member

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.

@thekingn0thing thekingn0thing modified the milestones: Backlog, PowerMock 1.6.6 Jul 24, 2016
@thekingn0thing
Copy link
Member

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

@thekingn0thing thekingn0thing 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
Projects
None yet
Development

No branches or pull requests

3 participants