I'm new to JMock and trying to get a simple unit test working through Scala. The test is mocking an interface and then setting some xpectations before executing a method on the mocked interface.
val context = new Mockery
val mockObj= context.mock(classOf[SomeClassInterface])
@Test def sometest = {
context.checking(
new Expectations() {
allowing (mockObj).doFunc1();
will(returnValue(someResponse);
allowing (mockObj).doFunc2(someResponse);
will(returnValue(someResponse));
allowing (mockObj).doFunc3(someResponse);
will(returnValue("Enabled"));
}
)
var status:String = mockObj.doSomething()
//context.assertIsSatisfied();
Assert.assertTrue(status.equalsIgnoreCase("Enabled"))
}
This results in the error;
unexpected invocation; mockObj.doSomething() ......... what happened before this; nothing!
Any ideas what is going wrong?
doSomething
method to be called. They only allowdoFunc1
,doFunc2
anddoFunc3
to be called on themockObj
(and you do not call these methods at all, so why allow them?). – Michał PolitowskiSomeClassInterface
is an interface, so there is no implementation ofdoSomething
. Anyway even if there is an implementation, the whole idea of creating a mock object is to not use it. – Michał Politowski