Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] How to test a method that is wrapped in a private method?

sparks

2008-07-02

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi all,
I am quite new to jMock and I am using jMock 2.4.0.

I am testing a service class which uses a
DAO object to read and write data and
the DAO object has been mocked out.

The service has a private method which delegates
all the calls to the DAO
object. The code is like following:

public class ServiceClass {
  private DAO dao;

  public void aOperation(){
    //some logics here
    updateData(data);
  }

  public void anotherOperation(){
    //some other logics here
    updateData(data);
  }

  private void updateData(Data someData){
    //pre processing......

    dao.update(someData);

    //post processing......
  }
}

Now the problem is:

when I specify the Expectations should
include one call to "dao.update(someData)",
the test never passes.

The reason that the test fails is that
"expected exactly 1 time, never invoked
dao.update(someData)......".

I am wondering if I'm on the right track to write
tests for this type of methods?

Thanks in advanced!


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

  http://xircles.codehaus.org/manage_email


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