Created
June 16, 2010 02:05
-
-
Save brian428/440032 to your computer and use it in GitHub Desktop.
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 org.swizframework.testapp.control | |
{ | |
import org.swizframework.testapp.event.MyEvent; | |
import flash.events.IEventDispatcher; | |
public class MyController | |
{ | |
[Dispatcher] | |
public var dispatcher : IEventDispatcher; | |
public var didSomething : Boolean = false; | |
[EventHandler( event="MyEvent.CONTROLLER_ACTION_REQUESTED" )] | |
public function handleAction() : void | |
{ | |
didSomething = true; | |
dispatcher.dispatchEvent( new MyEvent( MyEvent.CONTROLLER_ACTION_COMPLETE ) ); | |
} | |
} | |
} | |
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 org.swizframework.testapp.event | |
{ | |
import flash.events.Event; | |
public class MyEvent extends Event | |
{ | |
public static const CONTROLLER_ACTION_REQUESTED : String = "controllerActionRequested"; | |
public static const CONTROLLER_ACTION_COMPLETE : String = "controllerActionComplete"; | |
public function MyEvent(type:String) | |
{ | |
super(type, true, false); | |
} | |
} | |
} | |
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 org.swizframework.testapp.control | |
{ | |
import org.swizframework.testapp.MyController; | |
import org.swizframework.testapp.event.MyEvent; | |
import org.flexunit.Assert; | |
import org.flexunit.async.Async; | |
import org.swizframework.core.*; | |
import org.swizframework.utils.test.AutowiredTestCase; | |
public class MyControllerTestCase extends AutowiredTestCase | |
{ | |
private var myController : MyController; | |
[Before] | |
/** | |
* Create the object under test, create Swiz configuration, and build the Swiz context | |
* so that it can process the test objects as beans. | |
*/ | |
override public function constructSwizContext() : void | |
{ | |
myController = new MyController(); | |
swizConfig = new SwizConfig(); | |
swizConfig.eventPackages = "org.swizframework.testapp.event.*"; | |
beanProviders = [new BeanProvider( [myController] )]; | |
super.constructSwizContext(); | |
} | |
[After] | |
public function cleanUp():void | |
{ | |
myController = null; | |
} | |
[Test(async)] | |
public function testControllerActionRequested() : void | |
{ | |
Assert.assertTrue( "Controller property is already true.", myController.didSomething == false ); | |
Async.handleEvent( this, swiz.dispatcher, MyEvent.CONTROLLER_ACTION_COMPLETE, checkEvent ); | |
swiz.dispatcher.dispatchEvent( new MyEvent( MyEvent.CONTROLLER_ACTION_REQUESTED ) ); | |
} | |
private function checkEvent( event : Event, passThroughData : Object ) : void | |
{ | |
Assert.assertTrue( "Controller property was not updated.", myController.didSomething == true ); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment