Menu

#12 Verify my mock using ASMock

open
nobody
None
5
2010-10-28
2010-10-28
Praveen
No

How should i Verify my mock using ASMock . Is there any wrong thin I did .

-------------code starts here ------------

[Before(async)]
public function setUp():void
{
_login = new Login();
repository = new MockRepository();
mockRemoteService = IRemoteService(repository.createStub(IRemoteService));
_login.remoteService = mockRemoteService;
Async.proceedOnEvent( this, _login, FlexEvent.CREATION_COMPLETE, LONG_TIME );
UIImpersonator.addChild(_login );
}

[After(async)]
public function tearDown():void
{
UIImpersonator.removeChild(_login);
_login = null;
mockRemoteService =null;
repository.backToRecordAll();
repository =null;

}

[Test(async)]
public function testLogin():void {

var passThroughData:Object = new Object();
passThroughData.username ="Raman";
passThroughData.password ="x";
passThroughData.reponame ="Crystal";
SetupResult.forCall(mockRemoteService.login(null,null,null,null,null,null)).returnValue(null);

_login.usernameTextField.textValue="Raman";
_login.passwordTextField.textValue="x";

var repositoryListData : Array = new Array();
repositoryListData.push("Crystal","Crystal");

var networkLocationListData : Array = new Array();
networkLocationListData.push({id:"id", location:"india"});
_login.repositoryListComboBox.dataProvider =repositoryListData;
_login.networkLocationListComboBox.dataProvider = networkLocationListData;
_login.loginButton.enabled = true;

trace('_login.loginButton.enabled '+_login.loginButton.enabled );

repository.replay(mockRemoteService);

Async.handleEvent( this, _login, "loginRequested", handleLoginEvent, LONG_TIME, passThroughData );
_login.loginButton.dispatchEvent( new MouseEvent( 'click', true, false ) );

}

private function handleLoginEvent(event:Event, passThroughData:Object ):void
{
trace("handle "+event.target.toString());
repository.verify(mockRemoteService);
Assert.assertEquals( passThroughData.username, event.target.usernameTextField.textValue );
Assert.assertEquals( passThroughData.password, event.target.passwordTextField.textValue );
}

-------------code ends ------------

Error: This action is invalid when the mock object is in verified state.
at asmock.framework.impl.stub::StubVerifiedMockState/invalidInVerifiedState()
at asmock.framework.impl.stub::StubVerifiedMockState/methodCall()
at asmock.framework::MockRepository/methodCall()
at asmock.framework::ASMockInterceptor/intercept()
at org.floxy::InterceptorProxyListener/methodExecuted()
at asmock.generated::IRemoteService49467B09DB2D4CF010CF19D17298F84AA645A9A1/addEventListener()
at com.emc.documentum.mediaspace.client.mxml::Login/onClickResultHandler()[C:\mws\MediaWorkSpace\Main\projects\FlexBuilder\MediaWorkSpace\src\com\emc\documentum\mediaspace\client\mxml\Login.mxml:734]
at com.emc.documentum.mediaspace.client.mxml::Login/__loginButton_click()[C:\mws\MediaWorkSpace\Main\projects\FlexBuilder\MediaWorkSpace\src\com\emc\documentum\mediaspace\client\mxml\Login.mxml:1099]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:12266]
at com.emc.documentum.mediaspace.test.testcases.temp::NewLoginTestCase/testLogin()[C:\mws\MediaWorkSpace\Main\projects\FlexBuilder\MediaWorkSpace\src\com\emc\documentum\mediaspace\test\testcases\temp\NewLoginTestCase.as:88]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at flex.lang.reflect::Method/apply()[E:\hudson\jobs\FlexUnit4-Flex3.5\workspace\FlexUnit4\src\flex\lang\reflect\Method.as:208]

Discussion

  • Praveen

    Praveen - 2010-10-28
     
  • Richard Szalay

    Richard Szalay - 2010-11-01

    Hi Praveen,

    This probably belongs on the forum, but I'll have a look here anyway.

    In relation to your actual problem, it looks like something is calling a property/method on the IRemoteService after the login event is raised, this is likely happening in your UI component.

    However, here's a few things that jump out at me that you might want to address:

    - You don't need to call verify if you aren't using Expect (SetupResult means it doesn't *have* to be called)

    - Your setup for mockRemoteService.login passes nulls into every argument, but you don't call ignoreArguments. This means that it will pick up that Setup if the component actually passes in nulls for each argument. Having said that ...

    - Stubs return null (or the equivalent) for all method calls by default, so you don't need to setup a result that returns null for a stub.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.