0

I can't find my mistake, hope someone can help me out. I am trying to unit test my actionscript application using ASMock. I want to perform an asynchron test, but I don't get my mocked function to dispatch. this is what I did:

[Test(async,timeout="5000")]
public function testFailedIDResponse() : void {
  var mockRepository : MockRepository = new MockRepository();

// Record

var oMock:ConnectionProcessor  = ConnectionProcessor(mockRepository.createStub(ConnectionProcessor));
oMock.addEventListener("ConnectionProcessor.LOGICALERROR", Async.asyncHandler(this, onWrongID, 5000)); 
SetupResult.forCall(oMock.logigalErrorCode).returnValue("NOT_FOUND");
SetupResult.forEventDispatcher(oMock);
SetupResult.forCall(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
mockRepository.replayAll();
oMock.load();

but the event never arrives at my onWrongID handler. where is my error? thanks a lot guys!

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
tasovi
  • 11
  • 4

2 Answers2

1

You need to move your call to addEventListener until after replayAll. As it stands, it's just recording your call to addEventListener.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
0

You just have to call the dispatchEvent-method from your mocked object.

e.g.

oMock.dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));

Then your class/method/... under test will be able to handle the event.

or if you expect the load method to be called in somewhere before you could work with

Expect.call(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));

hope that helped. br,

gotti00
  • 101
  • 6