drewbourne / mockolate

fake chocolate, mock objects and test spies for AS3
http://mockolate.org/
MIT License
146 stars 26 forks source link

Unable to mock subclasses of Bitmap #62

Open weltraumpirat opened 12 years ago

weltraumpirat commented 12 years ago

I have several subclasses of Bitmap I need to use for a complex pixel transformation, and I've run into the following problem:

drewbourne commented 12 years ago

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 < reply@reply.github.com

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 the pixelSnapping argument must not be null. 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 null result if I try nice(Bitmap, "", [null, "auto", true]);

Reply to this email directly or view it on GitHub: https://github.com/drewbourne/mockolate/issues/62