Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Newbie question: Expectations and object references

jim.s

2009-10-01

Replies: Find Java Web Hosting

Author LoginPost Reply

Hello,

I'm new to JMock (using with TestNG) and I have a question about a the
following scenario:

I am testing a dao that takes a parameter and then creates the object that
will be persisted.

public class TestService {

  ITestDao testDao;

  public void save(KeyClass key) {

    TestClass testClass = new TestClass(key);
    testDao.save(testClass);
  }
}

Here is what my test looks like, at the moment.

class TestService {

 public void testClassCreate() {
   
    final ITestDao testDao = context.mock(ITestDao.class);
   
    TestService testService = new TestService();
    testService.setTestDao(testDao);

    final TestClass testClass = new TestClass(new KeyClass("testkey"));
   
    context.checking(new Expectations() {{
      oneOf (registryDao).save(testClass);
    }});
     
    context.assertIsSatisfied();
   
  }
}

When I run this I get something similar to the following:

FAILED: testClassCreate
not all expectations were satisfied
expectations:
expected once, never invoked:
iTestDao.save(<com.xxx.xxx.xxxx.domain.TestClass@(protected)>);


So, I think that the issue is that the TestClass instance being saved isn't
the same object reference as the actual saved TestClass (due to object
creation using the key parameter).

Is there any way to handle this? I've messed around with Expectations, but
no luck. Do I need a custom matcher?

Any help appreciated!

Thanks,
Jim

--
Sent from the jMock - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.