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

Using PowerMockRunner, @InjectMocks fails when trying to inject final fields #526

Closed
johanhaleby opened this issue Jul 25, 2015 · 2 comments

Comments

@johanhaleby
Copy link
Collaborator

From sbekkhu...@gmail.com on July 18, 2014 13:28:54

What steps will reproduce the problem? 1. Have a class with a final field, and a constructor initializing it
2. Create a test using PowerMockRunner, and mock the field, then using @Injectmocks over instance of the class to test
3. During runtime, you'll see that the instance of the mock created in your test is not the one getting injected What is the expected output? What do you see instead? The mock-instance I create in my test should be injected What version of the product are you using? On what operating system? 1.5.
Ubuntu 14.04. Please provide any additional information below. If not using PowerMockRunner (i.e. MockitoJUnitRunner or just regular JUnit), it works as it should

Original issue: http://code.google.com/p/powermock/issues/detail?id=506

@johanhaleby
Copy link
Collaborator Author

From johan.ha...@gmail.com on August 24, 2014 23:02:16

InjectMocks was not supported but in the next version it will be (but you need to prepare the class for test if it's final)

Status: Fixed

@johanhaleby
Copy link
Collaborator Author

From sbekkhu...@gmail.com on August 24, 2014 23:17:14

Only the fields were final not the class.

Awesome that PowerMock will support this! Any idea when the release will happen?

Just out of curiosity, what do you mean by "InjectMocks was not supported"? If we made the field non-final, it worked fine in our case. Or did you mean Injecting mocks into final fields?

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

1 participant