Unable to mock subclasses of Bitmap
I have several subclasses of Bitmap I need to use for a complex pixel transformation, and I've run into the following problem:
- If I use the
[Mock]annotation only, the test crashes and complains that thepixelSnappingargument must not benull. The funny thing is: all Bitmap constructor arguments have a default value, and so do the constructor args of my derived class. - If I use
[Mock(args="constructorArgs")], I do not get any errors, and I verified that theconstructorArgsfunction (which returns[null, "auto", true]) is called correctly. But instead of a mock object,nullis assigned to the variable. - I get the same
nullresult if I trynice(Bitmap, "", [null, "auto", true]);
In the first case with just [Mock] Mockolate will inject null for all
constructor parameters as the describeType() reflection information does
not indicate which parameters are required or optional. I will be improving
this situation shortly by using the as3-commons-bytecode library for
reflection and proxy generation.
In the second case with [Mock(args="constructorArgs")], it looks like you
are doing the correct thing. I will need to investigate further.
To discuss this issue at a higher level my suggestion is to avoid mocking the runtime classes, such as Bitmap. Instead introduce an interface for the manipulations you intend to perform, eg: IPixelTranformable which mirrors the API of the Bitmap methods you want to use, then type to that interface instead of the concrete Bitmap class and create a small extention class of Bitmap which implements the IPixelTransformable.
On Sat, Jun 2, 2012 at 12:58 AM, weltraumpirat < [email protected]
wrote:
I have several subclasses of Bitmap I need to use for a complex pixel transformation, and I've run into the following problem:
- If I use the
[Mock]annotation only, the test crashes and complains that thepixelSnappingargument must not benull. The funny thing is: all Bitmap constructor arguments have a default value, and so do the constructor args of my derived class.- If I use
[Mock(args="constructorArgs")], I do not get any errors, and I verified that theconstructorArgsfunction (which returns[null, "auto", true]) is called correctly. But instead of a mock object,null` is assigned to the variable.- I get the same
nullresult if I trynice(Bitmap, "", [null, "auto", true]);
Reply to this email directly or view it on GitHub: https://github.com/drewbourne/mockolate/issues/62