0

Ok - I've got a bit of a complicated asMock setup here; I've got a PureMVC async command that is attempting to call another class that implements interfaces in order to set up some asmocks for development without the backend.

import test.mix.common.business.MockInterbahnServiceFactory;

public class InitMockInterbahnServiceFactory extends AsyncCommand{
     public static var mockServiceFactory:MockInterbahnServiceFactory = new MockInterbahnServiceFactory();

    override public function execute(notification:INotification):void{
        var serviceResult:IEventDispatcher = mockServiceFactory.mockRepository.prepare([EchoBusinessObjects, SendBusinessObjects]);
        //serviceResult.addEventListener(Event.COMPLETE, onComplete);



    }

    private function onComplete(event:Event):void{
        mx.controls.Alert.show("COMPLETE!");
        var logMessage:String = "4  MOCK   SERVICE FACTORY MOCKED !!!!!";
        sendNotification( MixConstants.LOG_OUTPUT, logMessage );    
        //sendNotification(MixConstants.INTERBAHN_CONNECTED, mockServiceFactory);
    //  commandComplete() ;
    }
}

This is actually trying to set up a MockRepositoryFactory:

public class MockInterbahnServiceFactory implements ServiceFactory
{
    [Mock] public static var withMocks : Array = [
        SendBusinessObjects, EchoBusinessObjects
    ];

    //public static var mockRepository:MockRepository ;//= new MockRepository();
    public var mockSendBusinessObjects:SendBusinessObjects;
    public var mockEchoBusinessObjects:EchoBusinessObjects ;
    public var mockRepository:MockRepository;



    public function MockInterbahnServiceFactory(){
        mockRepository = new MockRepository();
        prepareMocks();
    }

    public function prepareMocks():void{
        var prepareDispatcher:IEventDispatcher = mockRepository.prepare([SendBusinessObjects, EchoBusinessObjects]);
        prepareDispatcher.addEventListener(Event.COMPLETE, setupMocks);
    }

    public function setupMocks(event:Event):void{
        mockSendBusinessObjects = SendBusinessObjects(mockRepository.create(SendBusinessObjects));
        mockEchoBusinessObjects = EchoBusinessObjects(mockRepository.create(EchoBusinessObjects));

        SetupResult.forCall(mockSendBusinessObjects.sendOrder(new Order())).returnValue('wee');

    }

    public function createSendBusinessObjectService():SendBusinessObjects{

        return mockSendBusinessObjects;
    }

    public function createEchoBusinessObjectService():EchoBusinessObjects{

        return mockEchoBusinessObjects;
    }

}

}

And at some point this factory is going to get passed around and utilized for the send / receive endpoints for multiple communications (true backend being a scala one).

I'm getting this error:

ArgumentError: returnValue must be assignable from :void
at asmock.framework.expectations::AbstractExpectation/set returnValue()[C:\Users\Richard\SVN\asmock\trunk\source\ASMock\src\asmock\framework\expectations\AbstractExpectation.as:107]
at asmock.framework::MethodOptions/returnValue()[C:\Users\Richard\SVN\asmock\trunk\source\ASMock\src\asmock\framework\MethodOptions.as:134]
at test.mix.common.business::MockInterbahnServiceFactory/setupMocks()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/trunk/src/test/mix/common/business/MockInterbahnServiceFactory.as:56]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at Function/org.floxy:ProxyRepository/org.floxy:IProxyRepository:prepare/org.floxy:swfLoadedHandler()[C:\transfer\IdeaProjects\as3-interbahn\floxy\main\as3\src\org\floxy\ProxyRepository.as:218]

I'm assuming this is because of the interface functions I'm stubbing?

public interface SendBusinessObjects {
     function sendFirmExchangePermission(frp:FirmExchangePermission):void ; 
     function sendFirm(f:Firm):void ;
     function sendExchange(ex:Exchange):void ;
     function sendFXConversion(fx:FXConversion):void ;
     function sendInstrument(ins:Instrument):void ;
     function sendQuote(q:Quote):void ;
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
grimmwerks
  • 491
  • 1
  • 6
  • 21

1 Answers1

1

It looks to me like SendBusinessObjects returns void, but you are calling returnValue when you are mocking the call to it. Remove the returnValue('wee') call and it should work as expected.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237