Closed GoogleCodeExporter closed 8 years ago
Hi,
Actually this is expected, this is a side effect of the way Objenesis is using
JVM internals to instantiate our generated classes. As Objenesis uses tricks
that bypasses default constructor in order to create an instance of an object.
This is necessary to create mock instances. ANd it shouldn't be an issue for
standard mock as mock are about interactions with methods not fields.
However that being said for partial mocks it might be an issue if someone
intends to use real method.
Note that not only final fields are affected but all fields that have a non
default value.
I'm sorry but I don't think there is a way to instantiate a proxy class, while
still executing the class init constructor. So I will set this issue to WontFix.
If you have a known way to perform such I'd be happy to know how to do it, talk
to the guys at Objenesis.
Cheers,
Brice
Original comment by brice.du...@gmail.com
on 3 Jan 2013 at 11:09
Thanks for the detailed explanation.
I understand the constraints, and there is I believe a workaround that
involves reflection.
But, like you mention, if mockito/objenesis uses dynamic way of creating
mocks via proxy classes, I agree reflection would be possible to do within
the mockito framework - it'd have to be written in the test itself.
I discovered this when a test started failing due to a dependency on an
abstract class with a final field *and* a final method, which forced a
partial mock strategy to be used.
Original comment by anu.glob...@gmail.com
on 3 Jan 2013 at 9:04
Correction: "...I agree reflection would *NOT *be possible to do within the
mockito framework...
Original comment by anu.glob...@gmail.com
on 3 Jan 2013 at 9:06
Original issue reported on code.google.com by
anu.glob...@gmail.com
on 28 Dec 2012 at 4:38