Created
August 8, 2011 23:20
-
-
Save drewbourne/1133025 to your computer and use it in GitHub Desktop.
Dispatching Events with Mockolate Mocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mockolate.example | |
{ | |
import flash.events.Event; | |
import mockolate.mock; | |
import mockolate.runner.MockolateRule; | |
import org.flexunit.assertThat; | |
import org.hamcrest.object.isFalse; | |
import org.hamcrest.object.isTrue; | |
public class DispatchingEvents | |
{ | |
[Rule] | |
public var mocks:MockolateRule = new MockolateRule(); | |
[Mock] | |
public var injected:InjectedClass; | |
public var target:TargetClass; | |
[Before] | |
public function setup():void | |
{ | |
mock(injected).asEventDispatcher(); | |
target = new TargetClass(); | |
target.injected = injected; | |
} | |
[Test] | |
public function afterInjectedIsComplete_targetWasEventFired_shouldBeTrue():void | |
{ | |
assertThat("before injected is complete wasEventFired should be false", | |
target.wasEventFired, isFalse()); | |
injected.dispatchEvent(new Event(Event.COMPLETE)); | |
assertThat("after injected is complete wasEventFired should be true", | |
target.wasEventFired, isTrue()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mockolate.example | |
{ | |
import flash.events.EventDispatcher; | |
[Event(name="complete", type="flash.events.Event")] | |
public class InjectedClass extends EventDispatcher | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mockolate.example | |
{ | |
import flash.events.Event; | |
public class TargetClass | |
{ | |
private var _injected:InjectedClass; | |
private var _wasEventFired:Boolean; | |
public function set injected(value:InjectedClass):void | |
{ | |
_injected = value; | |
_injected.addEventListener(Event.COMPLETE, injected_complete); | |
} | |
private function injected_complete(event:Event):void | |
{ | |
_wasEventFired = true; | |
} | |
public function get wasEventFired():Boolean | |
{ | |
return _wasEventFired; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment