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

Mocking and stubbing FileReference.data fails in Flex project #66

Open
luddet opened this issue Dec 13, 2012 · 0 comments
Open

Mocking and stubbing FileReference.data fails in Flex project #66

luddet opened this issue Dec 13, 2012 · 0 comments

Comments

@luddet
Copy link

luddet commented Dec 13, 2012

The code below works in a Flex Library Project but fails in a Flex Project.

package flexUnitTests
{
    import flash.net.FileReference;
    import flash.utils.ByteArray;

    import mockolate.runner.MockolateRunner;
    import mockolate.stub;

    import org.flexunit.assertThat;
    import org.flexunit.asserts.fail;
    import org.hamcrest.object.equalTo;
    import org.hamcrest.object.instanceOf;
    import org.hamcrest.object.notNullValue;
    import org.hamcrest.object.sameInstance;

    MockolateRunner;

    [RunWith("mockolate.runner.MockolateRunner")]
    public class FileReferenceMockTests {

        [Mock]
        public var _fileRef:FileReference;

        [Test]
        public function TestMockFileReference():void {
            var bytes:ByteArray = new ByteArray();

            stub(_fileRef).getter("data").returns(bytes);
            stub(_fileRef).getter("name").returns("the name");

            assertThat(_fileRef.data, instanceOf(ByteArray));
            assertThat(_fileRef.data, sameInstance(bytes));
            assertThat(_fileRef.name, equalTo("the name"));
        }
    }
}

Specifically, it's the data property that is handled differently. In the Flex project it always returns null. If I set a breakpoint after the stub-statements the fileRef looks like this:

  • _fileRef mockolate.generated.FileReference32E51D...
    • [inherited]
      • data = null
    • creationDate = null
    • creator = null
    • modificationDate = null
    • name = "the name"
    • __ proxy __ = InterceptorProxyListener
    • size = 0
    • type = null

I'm using FlashBuilder 4.6 and Flex Framework 4.6.

Update:
I have tested with Flex versions 4.1 and 4.5. Same result.
I have also tested with a Flex Project run as Air Application, that works. So the problem seems to appear only when run in a browser. (I have tested both Firefox and Safari)

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

1 participant