Skip to content

Instantly share code, notes, and snippets.

@brian428
Created June 16, 2010 02:05
Show Gist options
  • Save brian428/440032 to your computer and use it in GitHub Desktop.
Save brian428/440032 to your computer and use it in GitHub Desktop.
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 ) );
}
}
}
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);
}
}
}
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