Skip to content

Commit

Permalink
Added Async.delayCall
Browse files Browse the repository at this point in the history
  • Loading branch information
destroytoday committed Jan 8, 2011
1 parent 0e3d166 commit 176f243
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
23 changes: 23 additions & 0 deletions FlexUnit4/src/org/flexunit/async/Async.as
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
package org.flexunit.async
{
import flash.events.IEventDispatcher;
import flash.events.TimerEvent;
import flash.net.Responder;
import flash.utils.Timer;

import mx.rpc.IResponder;

Expand Down Expand Up @@ -212,5 +214,26 @@ package org.flexunit.async

return asyncHandlingStatement.asyncNativeResponder( resultHandler, faultHandler, timeout, passThroughData, timeoutHandler );
}

/**
* Calls a method after a given delay.
* @param testCase The current asynchronous test case.
* @param callback The function that will be executed if the <code>delay</delay> has been reached.
* @param delay The length of time, in milliseconds, before calling the <code>callback</code>.
*/
public static function delayCall(testCase:Object, callback:Function, delay:Number):void
{
var asyncHandlingStatement:IAsyncHandlingStatement = AsyncLocator.getCallableForTest( testCase );
var timer:Timer = new Timer(delay, 1);
var handler:Function;

handler = asyncHandlingStatement.asyncHandler( function(event:TimerEvent, object:Object):void
{
callback();
}, delay + 100.0);

timer.addEventListener( TimerEvent.TIMER_COMPLETE, handler, false, 0, true );
timer.start();
}
}
}
4 changes: 2 additions & 2 deletions FlexUnit4Test/.actionScriptProperties
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<actionScriptProperties mainApplicationPath="UIRunner.mxml" projectUUID="c0791c78-cb1b-4837-9e08-e5a4373e5714" version="6">
<actionScriptProperties analytics="false" mainApplicationPath="UIRunner.mxml" projectUUID="c0791c78-cb1b-4837-9e08-e5a4373e5714" version="7">
<compiler additionalCompilerArguments="-locale en_US -define=CONFIG::useFlexClasses,true" autoRSLOrdering="false" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="bin-debug" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
<compilerSourcePath/>
<libraryPath defaultLinkType="1">
<libraryPathEntry kind="4" path=""/>
<libraryPathEntry kind="1" linkType="1" path="libs"/>
<libraryPathEntry kind="3" linkType="1" path="/FlexUnit4/bin/FlexUnit4.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="/FlexUnit4CIListener/bin/FlexUnit4CIListener.swc" useDefaultLinkType="false"/>
<libraryPathEntry kind="3" linkType="1" path="/FlexUnit4UIListener/bin/FlexUnit4UIListener.swc" useDefaultLinkType="false"/>
</libraryPath>
<sourceAttachmentPath/>
Expand All @@ -17,4 +16,5 @@
</applications>
<modules/>
<buildCSSFiles/>
<flashCatalyst validateFlashCatalystCompatibility="false"/>
</actionScriptProperties>
7 changes: 7 additions & 0 deletions FlexUnit4Test/src/org/flexunit/async/cases/AsyncASCase.as
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@ package org.flexunit.async.cases
//Verify expectations were met
asyncHandlingStatementMock.mock.verify();
}

// In all honesty, I'm not sure how I should test this...
[Ignore]
[Test(description="Ensure the delayCall function is correctly called")]
public function delayCallTest():void {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package org.flexunit.async.cases

//Set expectations
asyncHandlingStatementMock.mock.method("asyncResponder").withArgs(responder, timeout, passThroughData, timeoutHandler).once.returns(responderMock);

Async.asyncResponder(testCase, responder, timeout, passThroughData, timeoutHandler);

//Verify expectations were met
Expand Down

0 comments on commit 176f243

Please sign in to comment.