Created
November 9, 2011 10:47
-
-
Save drewbourne/1351099 to your computer and use it in GitHub Desktop.
Mockolate Event dispatching example for SlevinBE
This file contains hidden or 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.examples.slevinbe | |
{ | |
import flash.events.IEventDispatcher; | |
import mockolate.runner.MockolateRule; | |
import org.flexunit.assertThat; | |
import org.hamcrest.object.isTrue; | |
public class EventDispatching | |
{ | |
[Rule] | |
public var mocks:MockolateRule = new MockolateRule(); | |
[Mock] | |
public var dispatcher:IEventDispatcher; | |
public var target:Target; | |
[Before] | |
public function setup():void | |
{ | |
mocks.mock(dispatcher).asEventDispatcher(); | |
target = new Target(); | |
target.dispatcher = dispatcher; | |
} | |
[Test] | |
public function target_should_be_updated_after_dispatcher_complete():void | |
{ | |
dispatcher.dispatchEvent(new Event(Event.COMPLETE)); | |
assertThat(target.isUpdated, isTrue()); | |
} | |
} | |
} | |
import flash.events.Event; | |
import flash.events.IEventDispatcher; | |
internal class Target | |
{ | |
private var _isUpdated:Boolean; | |
public function set dispatcher(dispatcher:IEventDispatcher):void | |
{ | |
dispatcher.addEventListener(Event.COMPLETE, _complete); | |
} | |
public function get isUpdated():Boolean | |
{ | |
return _isUpdated; | |
} | |
private function _complete(event:Event):void | |
{ | |
_isUpdated = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment