how8586 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 reported on code.google.com by sbekkhu...@gmail.com on 18 Jul 2014 at 11:28

GoogleCodeExporter commented 9 years ago
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)

Original comment by johan.ha...@gmail.com on 25 Aug 2014 at 6:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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?

Original comment by sbekkhu...@gmail.com on 25 Aug 2014 at 6:17