Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought

Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / General Discussion / Unit Testing Mediators on: September 11, 2008, 01:19:51
Does anyone test mediators?  I've been running into a specific problem, that I hope you can help me with.

I have been trying to create a mock view component that I can use to send an event to the mediator that I'm testing.  In the TestCase, I register the mediator with the facade like so:

  var mockAddressForm:MockAddressForm = new MockAddressForm;
  facade.registerMediator(new AddressMediator(mockAddressForm));

I've been following the standard pattern of creating mediators that have a getter method that returns the view component.  So the mediator that I'm trying to test (AddressMediator) has the following constructor and getter method:

  public function AddressMediator( viewComponent:Object ) {
    super( NAME, viewComponent );
    // Add the events we want to hear from the viewComponent
    viewComponent.addEventListener( AddressForm.SAVE, onSave);
  // Cast the viewComponent as the appropriate mxml component so we can reference it.   
  private function get addressForm():AddressForm{
    return viewComponent as AddressForm;

The problem is that when the addressMediator makes reference to the viewComponent, it does so through the above getter.  The mock object that I have created is not the same class as the actual viewComponent.  So when this code in the mediator is called:

  private function onSave( event:Event ):void {
    sendNotification(ApplicationFacade.SAVE_STUFF, addressForm.stuff);

The addressForm getter returns null.  I'm assuming this is because of the mismatch in packages, which makes sense.  But that begs the question, what does everyone else do to test a mediator?

A whole other question is, is it worth the effort?

Thanks for your help!

Pages: [1]