« Return to Thread: Mocking Database Access - unexpected invocation

Mocking Database Access - unexpected invocation

by Winfried :: Rate this Message:

Reply to Author | View in Thread

I try to mock the access to my database to check some programmatical logic

the test looks like

try {
 context.checking(new Expectations() {{
  oneOf(mockDBGroup).getGroupByGroupId(pGroup.getGroupId(), newTransactionManagerImpl().getTransaction()); will(returnValue(pGroup));
  oneOf(mockDBUser).getUser(new DatabaseQueryBean(), new TransactionManagerImpl().getTransaction()); will(returnValue(pUserLoggedIn));
 }});
} catch (SQLException e) {
  e.printStackTrace();
  fail();
}

service.addGroupMember(pUserLoggedIn, pUser.getUserId(), pGroup.getGroupId(), pPassword, pRole);
context.assertIsSatisfied();

the omplementation of the group member method contains the following code

DatabaseQueryBean queryBean = new DatabaseQueryBean();
queryBean.addFilter( new FilterItem( "user_id", pUserId ) );
user = dbUser.getUser( queryBean, tx );

The problem now is that i get an unexpected invocation when i run this test. I asume that's becaus jmock expects a call with the the object instantiated in the test as parameter but gets a new object. Is this correct an is there any way avoiding to use the same object?

Thanks for any advice
wkurtz

 « Return to Thread: Mocking Database Access - unexpected invocation