Skip to content

Instantly share code, notes, and snippets.

@weyert
Created January 15, 2011 14:45
Show Gist options
  • Save weyert/780950 to your computer and use it in GitHub Desktop.
Save weyert/780950 to your computer and use it in GitHub Desktop.
Mock class for iModuleDelegate
public class MockModuleDelegate implements IModuleDelegate {
public function getTranslation( name: String, defaultValue: String = "" ): String {
if ( name == "title" ) {
return "Moduel Title";
} else if ( name = "currency" ) {
return "EUR";
}
// more resource strings here
}
public function getCacheItem( name: String ): Object { return null }
public function getAvailableCacheItems( name: String ): Array { return ["data1", "data2] }
}
var mockolateMaker:IEventDispatcher = prepare(IModuleDelegate);
mockolateMaker.addEventListener(Event.COMPLETE, prepareCompleteHandler);
private function prepareCompleteHandler(e:Event):void{
IEventDispatcher(e.target).removeEventListener(Event.COMPLETE, prepareCompleteHandler);
var moduleDelegate: IModuleDelegate = nice(IModuleDelegate);
mock(moduleDelegate).method("getTranslation").args("title").returns("Module Title");
mock(moduleDelegate).method("getTranslation").args("currency").returns("EUR");
trace("Forcing module delegate for the application");
this.delegate = moduleDelegate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment