| Author |
unexpected invocation error with mock objects
|
jeff mutonho
Ranch Hand
Joined: Apr 30, 2003
Posts: 271
|
|
The method getAccountByAccountKey below is where I'm getting the " unexpected invocation" error mockLinkedServiceAccountDao = mock(LinkedServiceAccountDao.class); mockLinkedServiceAccountDao.verify(); linkedServiceAccountDao = (LinkedServiceAccountDao) mockLinkedServiceAccountDao.proxy(); accountId = ((Account) linkedServiceAccountDao.getAccountByAccountKey(ban).get(0)).getId(); System.out.println("## accountId : " + accountId.toString()); mockLinkedServiceAccountDao.expects(once()).method("getAccountByAccountKey").with(eq(new Long(1))).will(returnValue(accountId)); junit ] Testcase: test1 took 0.14 sec [ junit ] FAILED [ junit ] mockLinkedServiceAccountDao: unexpected invocation [ junit ] Invoked: mockLinkedServiceAccountDao.getAccountByAccountKey("1234567890") [ junit ] Allowed: [ junit ] No expectations set [ junit ] org.jmock.core.DynamicMockError: mockLinkedServiceAccountDao: unexpected invocation [ junit ] Invoked: mockLinkedServiceAccountDao.getAccountByAccountKey("1234567890") [ junit ] Allowed: [ junit ] No expectations set [ junit ] at org.jmock.core.AbstractDynamicMock.mockInvocation( AbstractDynamicMock.java:95 -- What's causing this?
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
You need to *first* set the expectations (your last line), and *then* use the mock in your test. Moving to our testing forum...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: unexpected invocation error with mock objects
|
|
|