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

Unable to mock subclasses of Bitmap #62

Open
weltraumpirat opened this issue Jun 1, 2012 · 1 comment
Open

Unable to mock subclasses of Bitmap #62

weltraumpirat opened this issue Jun 1, 2012 · 1 comment

Comments

@weltraumpirat
Copy link

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 the constructorArgs function (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]);
@drewbourne
Copy link
Owner

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:
#62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants