src/asunit/runners/SuiteRunner.as in asunit4-4.2.2.pre vs src/asunit/runners/SuiteRunner.as in asunit4-4.2.3.pre

- old
+ new

@@ -1,64 +1,52 @@ package asunit.runners { + + import asunit.framework.IResult; + import asunit.framework.IRunner; + import asunit.framework.IRunnerFactory; + import asunit.framework.Result; + import asunit.framework.RunnerFactory; + import asunit.framework.SuiteIterator; + import asunit.util.Iterator; + import org.swiftsuspenders.Injector; + + import flash.display.DisplayObjectContainer; + import flash.events.Event; + import flash.events.EventDispatcher; + import flash.events.TimerEvent; + import flash.utils.Timer; - import asunit.framework.CallbackBridge; - import asunit.framework.IResult; - import asunit.framework.IRunner; - import asunit.framework.IRunnerFactory; - import asunit.framework.RunnerFactory; - import asunit.util.Iterator; - import asunit.framework.SuiteIterator; + public class SuiteRunner extends EventDispatcher implements IRunner { - import flash.display.DisplayObjectContainer; - import flash.events.Event; - import flash.events.EventDispatcher; - import flash.events.IEventDispatcher; - import flash.events.TimerEvent; - import flash.utils.Timer; - import flash.utils.getDefinitionByName; - - import p2.reflect.Reflection; - import p2.reflect.ReflectionMetaData; - - public class SuiteRunner implements IEventDispatcher, IRunner { - - [Inject] - public var bridge:CallbackBridge; + public var result:IResult; - protected var dispatcher:IEventDispatcher; protected var testClasses:Iterator; protected var timer:Timer; protected var visualContext:DisplayObjectContainer; protected var testMethod:String; + protected var injector:Injector; + protected var factory:IRunnerFactory; + + public function SuiteRunner(factory:IRunnerFactory = null, result:IResult = null, injector:Injector = null) { + timer = new Timer(0, 1); - private var _factory:IRunnerFactory; + this.injector = injector ||= new Injector(); + injector.mapValue(Injector, injector); + this.result = result ||= new Result(); + injector.mapValue(IResult, result); + this.factory = factory ||= injector.instantiate(RunnerFactory); + injector.mapValue(IRunnerFactory, factory); + } - public function SuiteRunner() { - timer = new Timer(0, 1); - dispatcher = new EventDispatcher(); - } - public function run(suite:Class, testMethod:String=null, visualContext:DisplayObjectContainer=null):void { this.visualContext = visualContext; this.testMethod = testMethod; runSuite(suite); } - public function shouldRunTest(testClass:Class):Boolean { - return bridge.shouldRunTest(testClass); - } - - public function set factory(factory:IRunnerFactory):void { - _factory = factory; - } - - public function get factory():IRunnerFactory { - return _factory ||= new RunnerFactory(); - } - protected function runSuite(suite:*):void { - testClasses = new SuiteIterator(suite, bridge); + testClasses = new SuiteIterator(suite); timer.addEventListener(TimerEvent.TIMER, runNextTest); runNextTest(); } @@ -95,31 +83,7 @@ * Template method that subclasses can override to perform some * operation when the run is complete. */ protected function onRunCompleted():void { } - - // BEGIN: Implement the IEvent Dispatcher Interface: - - public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void { - dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference); - } - - public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void { - dispatcher.removeEventListener(type, listener, useCapture); - } - - public function dispatchEvent(event:Event):Boolean { - return dispatcher.dispatchEvent(event); - } - - public function hasEventListener(type:String):Boolean { - return dispatcher.hasEventListener(type); - } - - public function willTrigger(type:String):Boolean { - return dispatcher.willTrigger(type); - } - - // END: Implement the IEvent Dispatcher Interface: } }