Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9001189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:24:11+00:00 2026-06-16T00:24:11+00:00

I am learning robotlegs framework, but this question is also I think of general

  • 0

I am learning robotlegs framework, but this question is also I think of general nature.

I have a Mediator class that listens for event on a button in View and on that event it dispatches a signal containing VO which contains properities from two TextField objects in View.

Below is mediator class.

button is a private variable that only has getter and no setter in View.

My Question is, how would I unit test this class?
1. to check if event comes that Signal is being dispatched…
2. when signal is dispatched, that it contains correct VO

I know that I need to use Mock, and I am using mockolate, but i am spinning in circle, because i don’t know how to mock a dispatched event from a button from view class?

Thanks for help

        public class LoginFormMediator extends Mediator {

            //---------------------------------------------------------------
            //  Public variables
            //---------------------------------------------------------------



            [Inject]
            public var view:LoginFormView;
            [Inject]
            public var authorizationSignal:AuthorizationSignal;


            //---------------------------------------------------------------
            //  Public Functions
            //---------------------------------------------------------------

            override public function initialize():void
            {
                view.button.addEventListener(MouseEvent.CLICK,onLogin,false,0,true);

            }



            //---------------------------------------------------------------
            //  Private methods
            //---------------------------------------------------------------
            private function onLogin(event:MouseEvent):void {
                var userInfo:UserInfo = new UserInfo(view.usernameField.text,view.passwordField.text);
                authorizationSignal.dispatch(userInfo);

            }

        }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:24:12+00:00Added an answer on June 16, 2026 at 12:24 am

    There’s a few possibilities:

    1/ don’t expose the button and let the mediator listen to it directly. The view should dispatch a specific, concrete event to which the mediator is listening and preferably this describes user intention, not user action. E.g: let the view dispatch a LoginFormViewEvent.LOGIN_REQUESTED or maybe a LoginFormViewEvent.CREDENTIALS_PROVIDED event.
    The reason why this is better is that it doesn’t tie your mediator to a specific implementation of your view. For instance, maybe later on you want to add some kind of validation rule that needs to be run before the credentials are dispatched. If you listen to the button directly you’ll either be writing the validation logic into the mediator, which is a definite no-no or you’ll need to refactor your view.

    A mediators job is to mediate between a view and the system, nothing more. It doesn’t need to know what UI elements are in the view, just pass data from the view to the system and vice versa.

    2/ Another possibility is to let the mediator pass the system-wide signal to the view, which does the dispatching and VO population.

    //mediator
    [Inject]
    public var view:LoginFormView;
    [Inject]
    public var authorizationSignal:AuthorizationSignal;
    
    override public function initialize():void{
        view.authorizationSignal = authorizationSignal;
    }
    
    //view
    public var authorizationSignal : ISignal;
    
    public function init():void{
        button.addEventlistener( MouseEvent.CLICK, button_clickHandler );
    }
    
    private function button_clickHandler( event : MouseEvent ) : void{
        var vo : UserInfo = new UserInfo( usernameField.text, passwordField.text);
        authorizationSignal.dispatch( vo );
    }
    

    I tend to make the signal conditionally instantiated and generic, to make the view more easily reusable. Like this:

    //view
    private var _authorizationSignal : ISignal;
    public function set authorizationSignal( value : ISignal ) : void{
        _authorizationSignal = value;
    }
    public function get authorizationSignal() : ISignal{
        return _authorizationSignal ||= new Signal();
    }
    

    Then the signal injection is optional and the view provides a default signal instance.

    3/ Or if you choose to stick to your original approach, you can mock the button the normal mockolate way. Let your view implement an interface where a getter for the button is declared. Map your mediator to the interface (which is good practice anyway) instead of the concrete view type. This way you can assign a mocked button to it in the test class, yet have the button encapsulated facing the mediator.

    Then, to have the mocked button dispatch the event:

    [Mock]
    public var mockButton : Button;
    
    //in setup 
    view.button = mockButton
    
    //in test
    mockButton.dispatch( new MouseEvent( MouseEvent.CLICK ) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I learning LINQ, and i want to use pending request, but i have this
learning Jquery and integrating with PHP - getting there, but have one last challenge
Currently learning Scheme/Racket and have problem running this piece of code. (if (or (<
For learning purposes I'm building a simple messaging program that I think can work
Learning Javascript and have a question about global variables. From my reading, most recommend
Learning C at University. This is not a homework, but I was trying to
Learning PHP and I have a question. How does one obtain an element from
Learning regex but this one gives me a headache. I need to match a
Learning Ruby. Needed to create a hash of arrays. This works... but I don't
Learning some VBA. So far, I've constructed this piece of code which should allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.