Hello,
I'm trying to get a handle on mocking w/ Mockito to and I keeping getting this error:
"Please make sure you specified a call to stub in given". Also, I cannot get mockito to work unless I add the mock directive
outside the class:
Here's a copy of my code:
here's the service class and method it's testing:
I'm completely stumped here and have been googling for days!!
-E
I'm trying to get a handle on mocking w/ Mockito to and I keeping getting this error:
"Please make sure you specified a call to stub in given". Also, I cannot get mockito to work unless I add the mock directive
outside the class:
Code:
[Mock(type="common.services.ScaleService")]
Here's a copy of my code:
Code:
package TDMSETestSuites.organWeights.tests
{
import common.interfaces.IScaleService;
import common.services.ScaleService;
import flash.events.EventDispatcher;
import flash.utils.Timer;
import flexunit.framework.Assert;
import mx.collections.ArrayCollection;
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.rpc.remoting.test.RemoteObjectStub;
import org.flexunit.async.Async;
import org.flexunit.async.TestResponder;
import org.flexunit.rules.IMethodRule;
import org.hamcrest.core.*;
import org.mockito.Mockito;
import org.mockito.integrations.*;
import org.mockito.integrations.flexunit4.MockitoRule;
import org.spicefactory.parsley.core.context.Context;
import org.spicefactory.parsley.dsl.context.ContextBuilder;
import org.spicefactory.parsley.flex.FlexConfig;
//so far, this, declaration, at this level is the only way it works- WHY??
[Mock(type="common.services.ScaleService")]
public class ScaleServiceTest extends TDMSETestBase
{
[Rule]
public var mockitoRule:IMethodRule = new MockitoRule();//mockito crucial
[Inject(id="roScale")]
public var injectedScaleRemoteObject:RemoteObject;
[Inject]
public var injectedScaleService:IScaleService;
[Inject]
public var iScaleService:IScaleService;
public var scaleService:ScaleService;
//---- mockito properties --------------------------------
//--------------------------------------------------------
private var mockScaleService:ScaleService;
private var mockScaleIService:IScaleService;
private var mockito:Mockito = new Mockito();
public var context:Context;
private var fault:Boolean=Boolean(false);
private var resultCheckTimer:Timer;
// The timer and result check timeouts
private static const TIMEOUT_MS:int = 4000;
private static const RESULT_CHECK_TIMEOUT_MS:int = 3500;
[Before]
public function setUp():void
{
//create base TDMSE parsley context
context = ContextBuilder.newBuilder()
.config(FlexConfig.forClass(TDMSEAppParsleyConfig))
.object(this)
.build
scaleService = new ScaleService();
mockScaleService = mock(ScaleService);
}
//---- MOCHITO TESTS ------------------------------------------------------------
//-------------------------------------------------------------------------------
[Test(async)]
public function mockitoGetScaleData1():void
{
var token:AsyncToken = mockScaleService.getScaleData(faultHandler);
mockito.given(mockScaleService.getScaleData).willReturn(token);
mockito.verify().that(mockScaleService.getScaleData(faultHandler));
}
//------------------------------------------------------------------------------
}
}
here's the service class and method it's testing:
Code:
public class ScaleService extends EventDispatcher implements IScaleService
{
[Inject(id="roScale")]
public var scaleService:RemoteObject;
public function getScaleData(getScaleDataFaultHandler:Function):AsyncToken
{
return scaleService.getScaleData().addResponder(new AsyncResponder(getScaleData_result, getScaleDataFaultHandler));
}
}
I'm completely stumped here and have been googling for days!!
-E