Strategies for using jMock on large projects?
Munro, Alec wrote:
>
> I'm just getting started with jMock, and the syntax is quite appealing
> to me, but I'm running into numerous challenges when trying to
> implement it on an existing fairly large project. I have a specific
> problem at the moment, but I'm really looking for any general
> strategies for larger projects, as the docs are fairly light.
>
> One of the things I have decided to do is create a mockXXXX method for
> each method under test, in addition to a testXXXX method. This
> mockXXXX method handles the setup for any mock objects for that
> method. This seemed the sensible way to handle a situation in which a
> number class methods were called frequently by other class methods.
Sounds a bit complicated for a unit test.
> However, when I have a method that is called twice within one test, I
> have to set up the mock objects used in that method twice (so I call
> my mockXXXX method twice). Unfortunately, it seems like jMock doesn't
> keep track of additive method expectations, so if this method is
> called twice with the same arguments, the second call will be unable
> to find a matching expecation. Of course, I can set the call to be
> expected atLeastOnce(), but the mockXXXX method doesn't know how many
> times it will be called, so it has no basis upon which to determine
> which of it's expectations should be set to atLeastOnce(). I can set
> all of the expectations to atLeastOnce(), but then I lose some
> specificity, and the test code becomes less clear, as it only calls
> the mockXXXX method once, rather than each time the corresponding
> method is expected to be called.
>
You need to use the id and after methods to enter constraints on method
call ordering e.g.
mock.expects(once()).method("foo").with(eq("p1")).id("foo p1");
mock.expects(once()).method("foo").after("foo p1").with(eq("p2"));
- Neil
By the way, it looks to me like you can't specify the ordering of
invocations across mocks, e.g.,
mockOne.expects(once()).method("foo").with(eq("p1")).id("foo p1");
mockTwo.expects(once()).method("foo").after("foo p1").with(eq("p2"));
Is there any way to do this? It seems like specifying ordering among mock
interactions can be valuable in a test case...
-----Original Message-----
From: Neil Swingler [mailto:neil@...]
Sent: Tuesday, April 04, 2006 12:37 PM
To: user@...
Subject: Re: [jmock-user] Strategies for using jMock on large projects?
Munro, Alec wrote:
>
> I'm just getting started with jMock, and the syntax is quite appealing
> to me, but I'm running into numerous challenges when trying to
> implement it on an existing fairly large project. I have a specific
> problem at the moment, but I'm really looking for any general
> strategies for larger projects, as the docs are fairly light.
>
> One of the things I have decided to do is create a mockXXXX method for
> each method under test, in addition to a testXXXX method. This
> mockXXXX method handles the setup for any mock objects for that
> method. This seemed the sensible way to handle a situation in which a
> number class methods were called frequently by other class methods.
Sounds a bit complicated for a unit test.
> However, when I have a method that is called twice within one test, I
> have to set up the mock objects used in that method twice (so I call
> my mockXXXX method twice). Unfortunately, it seems like jMock doesn't
> keep track of additive method expectations, so if this method is
> called twice with the same arguments, the second call will be unable
> to find a matching expecation. Of course, I can set the call to be
> expected atLeastOnce(), but the mockXXXX method doesn't know how many
> times it will be called, so it has no basis upon which to determine
> which of it's expectations should be set to atLeastOnce(). I can set
> all of the expectations to atLeastOnce(), but then I lose some
> specificity, and the test code becomes less clear, as it only calls
> the mockXXXX method once, rather than each time the corresponding
> method is expected to be called.
>
You need to use the id and after methods to enter constraints on method
call ordering e.g.
mock.expects(once()).method("foo").with(eq("p1")).id("foo p1");
mock.expects(once()).method("foo").after("foo p1").with(eq("p2"));
- Neil
By the way, it looks to me like you can't specify the ordering of invocations across mocks, e.g., mockOne.expects(once()).method("foo").with(eq("p1")).id("foo p1"); mockTwo.expects(once()).method("foo").after("foo p1").with(eq("p2")); Is there any way to do this? It seems like specifying ordering among mock interactions can be valuable in a test case... -----Original Message----- From: Neil Swingler [mailto:neil-1UmcnvSkb1kfv37vnLkPlQ@public.gmane.org] Sent: Tuesday, April 04, 2006 12:37 PM To: user-sXN/XchZ9OexIXFVlbCvtR2eb7JE58TQ@public.gmane.org Subject: Re: [jmock-user] Strategies for using jMock on large projects? Munro, Alec wrote:I'm just getting started with jMock, and the syntax is quite appealing to me, but I'm running into numerous challenges when trying to implement it on an existing fairly large project. I have a specific problem at the moment, but I'm really looking for any general strategies for larger projects, as the docs are fairly light. One of the things I have decided to do is create a mockXXXX method for each method under test, in addition to a testXXXX method. This mockXXXX method handles the setup for any mock objects for that method. This seemed the sensible way to handle a situation in which a number class methods were called frequently by other class methods.Sounds a bit complicated for a unit test.However, when I have a method that is called twice within one test, I have to set up the mock objects used in that method twice (so I call my mockXXXX method twice). Unfortunately, it seems like jMock doesn't keep track of additive method expectations, so if this method is called twice with the same arguments, the second call will be unable to find a matching expecation. Of course, I can set the call to be expected atLeastOnce(), but the mockXXXX method doesn't know how many times it will be called, so it has no basis upon which to determine which of it's expectations should be set to atLeastOnce(). I can set all of the expectations to atLeastOnce(), but then I lose some specificity, and the test code becomes less clear, as it only calls the mockXXXX method once, rather than each time the corresponding method is expected to be called.You need to use the id and after methods to enter constraints on method call ordering e.g. mock.expects(once()).method("foo").with(eq("p1")).id("foo p1"); mock.expects(once()).method("foo").after("foo p1").with(eq("p2")); - Neil
Coming back to this thread again after a while, hope you don't mind.
It's best to think of the tests as specifications.
You specify what C1 does. You specify what C2 does.
Some other class, D, composes C1 and C2 into a new abstraction.
That's an implementation detail: the specification for D just
describes what D does.
Hi Alec,
________________________________
From: Munro, Alec
Sent: Tuesday, April 04, 2006 6:25 PM
Subject: [jmock-user] Strategies for using jMock on large projects?
Hi List,
I'm just getting started with jMock, and the syntax is quite appealing to me, but I'm running into numerous
challenges when trying to implement it on an existing fairly large project. I have a specific problem at
the moment, but I'm really looking for any general strategies for larger projects, as the docs are fairly light.
One of the things I have decided to do is create a mockXXXX method for each method under test, in addition to a
testXXXX method. This mockXXXX method handles the setup for any mock objects for that method. This seemed
the sensible way to handle a situation in which a number class methods were called frequently by other
class methods.
However, when I have a method that is called twice within one test, I have to set up the mock objects used in
that method twice (so I call my mockXXXX method twice). Unfortunately, it seems like jMock doesn't keep
track of additive method expectations, so if this method is called twice with the same arguments, the
second call will be unable to find a matching expecation. Of course, I can set the call to be expected
atLeastOnce(), but the mockXXXX method doesn't know how many times it will be called, so it has no basis
upon which to determine which of it's expectations should be set to atLeastOnce(). I can set all of the
expectations to atLeastOnce(), but then I lose some specificity, and the test code becomes less clear, as
it only calls the mockXXXX method once, rather than each time the corresponding method is expected to be called.
Any ideas are very much appreciated. If you think I've overlooked something, please let me know.
________________________________
You might give a current snapshopt of jMock a try. It defines "exactly(n)" among a lot of other goodies.
Nevertheless you should consider your strategy. I made originally also the mistake to "count" the calls to
a method. Meanwhile I stub a lot of the methods. Think for yourself: Does it matter how often a getter is
called? Usually I use the setUp to stub methods for my mocks:
Mock mockType;
void setUp() throws Exception {
mockType = mock(Type.class);
mockType.stubs().method("getName").will(returnValue("john doe"));
}
If you write such tests, just consider wether your test should break, if a method is called a different time
after some code modification. If not, stub the method and you get much less brittle tests that concentrate
on the vitals.
- Jörg
Hi all,
I am new to JMock and have run in to this problem whose cause is unknown to me. Could some body help me debug this issue?
I am getting an error:
[junit] Testsuite: org.mediaslate.ogs.services.service.PingServiceTest
[junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
[junit] ------------- Standard Output ---------------
[junit] In setPingDAO :: mockPingDAO
[junit] In setPingDAO :: mockPingDAO
[junit] ------------- ---------------- ---------------
[junit] Testcase: testPingDatabase(org.mediaslate.ogs.services.service.PingServiceTest): FAILED
[junit] mockPingDAO: no match found
[junit] Invoked:
org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(<org.mediaslate.ogs.services.model.PingRequest <at> e2291[
[junit] requestTime=2006-04-05 14:58:31.078
[junit] ]>)
[junit] Allowed:
[junit] expected once: savePingRequest( same(<org.mediaslate.ogs.services.model.PingRequest <at> 2f0d54[
[junit] requestTime=2006-04-05 14:58:31.078
[junit] ]>) ), is void
[junit] org.jmock.core.DynamicMockError: mockPingDAO: no match found
[junit] Invoked: org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(<org.mediaslate.ogs.services.model.PingRequest <at> e2291[
[junit] requestTime=2006-04-05 14:58:31.078
[junit] ]>)
[junit] Allowe
d:
[junit] expected once: savePingRequest(
same(<org.mediaslate.ogs.services.model.PingRequest <at> 2f0d54[
[junit] requestTime=2006-04-05 14:58:31.078
[junit] ]>) ), is void
[junit] at org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
[junit] at org.jmock.core.CoreMock.invoke(Unknown Source)
[junit] at $Proxy4.savePingRequest(Unknown Source)
[junit] at org.mediaslate.ogs.services.service.impl.PingServiceImpl.pingDatabase(PingServiceImpl.java:91)
[junit] at org.mediaslate.ogs.services.service.PingServiceTest.testPingDatabase(PingServiceTest.java:46)
[junit] at org.jmock.core.VerifyingTestCase.runBare(Unknown Source)
[junit] TEST org.mediaslate.ogs.services.service.PingServiceTest FAILED
&n
bsp; [junit] Tests FAILED
DAO definately has a method: public void
savePingRequest(). What is causing JMock to thrown "No match found error" ?
Here is my code:
1. Test case:
public class PingServiceTest extends MockObjectTestCase {
private PingService pingService = new PingServiceImpl();
private Mock pingDao = null;
protected void setUp() throws Exception {
super.setUp();
//Create a MOCK object for PingDAO.
pingDao = new Mock(PingDAO.class);
//Set mock PingDAO for the ping service...
pingService.set
PingDAO((PingDAO)pingDao.proxy());
}
public void testPingApp() {
String message = pingService.pingApp();
assertEquals(message, PingService.OGRS_SERVER_MSG);
}
public void testPingDatabase() {
Timestamp ts = new Timestamp(System.currentTimeMillis());
PingRequest req = new PingRequest();
req.setRequestTime(ts);
pingDao.reset();
pingDao.expects(once()).method("savePingRequest").
with(same(req)).isVoid();
&n
bsp; String message = pingService.pingDatabase();
assertTrue(message.startsWith(PingService.OGRS_SERVER_MSG));
pingDao.verify();
}
}
This test case uses MOCK for PingDAO, the interface of which is here:
public interface PingDAO {
/**
* Gets the server date.
* <at> return current date on the server.
*/
public Timestamp getServerDate();
/**
* Saves specified <code>PingRequest</code>.
* <at> param aPingRequest a ping request to be saved.
*/
public void savePingRequest(PingRequest aPingRequest);
 
; /**
* Deletes a ping request from the database using
specified primary key.
* <at> param aTimestamp Timestamp that uniquely identifies the ping request.
*/
public void deletePingRequest(Timestamp aTimestamp);
/**
* Get the ping request using specified time stamp.
* <at> param aTimestamp Timestamp that uniquely identifies the ping request.
* <at> return <code>PingRequest</code> identified by the specified timestamp.
*/
public PingRequest getPingRequest(Timestamp aTimestamp);
}
Thanks in advance for your time and help...
Rajan
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
Desai,
My first suspicion would be that PingRequest.equals is not what you want
it to be.
David Saff
Desai Rajan wrote:
> Hi all,
>
> I am new to JMock and have run in to this problem whose cause is
> unknown to me. Could some body help me debug this issue?
>
> I am getting an error:
> [junit] Testsuite: org.mediaslate.ogs.services.service.PingServiceTest
> [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
> [junit] ------------- Standard Output ---------------
> [junit] In setPingDAO :: mockPingDAO
> [junit] In setPingDAO :: mockPingDAO
> [junit] ------------- ---------------- ---------------
> [junit] Testcase:
> testPingDatabase(org.mediaslate.ogs.services.service.PingServiceTest):
> FAILED
> [junit] mockPingDAO: no match found
> [junit] Invoked:
> org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(<org.mediaslate.ogs.services.model.PingRequest <at> e2291[
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>)
> [junit] Allowed:
> [junit] expected once: savePingRequest(
> same(<org.mediaslate.ogs.services.model.PingRequest <at> 2f0d54[
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>) ), is void
> [junit] org.jmock.core.DynamicMockError: mockPingDAO: no match found
> [junit] Invoked:
> org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(<org.mediaslate.ogs.services.model.PingRequest <at> e2291[
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>)
> [junit] Allowed:
> [junit] expected once: savePingRequest(
> same(<org.mediaslate.ogs.services.model.PingRequest <at> 2f0d54[
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>) ), is void
> [junit] at
> org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
> [junit] at org.jmock.core.CoreMock.invoke(Unknown Source)
> [junit] at $Proxy4.savePingRequest(Unknown Source)
> [junit] at
> org.mediaslate.ogs.services.service.impl.PingServiceImpl.pingDatabase(PingServiceImpl.java:91)
> [junit] at
> org.mediaslate.ogs.services.service.PingServiceTest.testPingDatabase(PingServiceTest.java:46)
> [junit] at org.jmock.core.VerifyingTestCase.runBare(Unknown Source)
> [junit] TEST org.mediaslate.ogs.services.service.PingServiceTest
> FAILED
> [junit] Tests FAILED
>
> DAO definately has a method: public void savePingRequest(). What is
> causing JMock to thrown "No match found error" ?
>
> Here is my code:
>
> 1. Test case:
> public class PingServiceTest extends MockObjectTestCase {
> private PingService pingService = new PingServiceImpl();
> private Mock pingDao = null;
>
> protected void setUp() throws Exception {
> super.setUp();
>
> //Create a MOCK object for PingDAO.
> pingDao = new Mock(PingDAO.class);
>
> //Set mock PingDAO for the ping service...
> pingService.setPingDAO((PingDAO)pingDao.proxy());
> }
>
> public void testPingApp() {
> String message = pingService.pingApp();
> assertEquals(message, PingService.OGRS_SERVER_MSG);
> }
>
> public void testPingDatabase() {
> Timestamp ts = new Timestamp(System.currentTimeMillis());
> PingRequest req = new PingRequest();
> req.setRequestTime(ts);
>
> pingDao.reset();
> pingDao.expects(once()).method("savePingRequest").
> with(same(req)).isVoid();
>
> String message = pingService.pingDatabase();
> assertTrue(message.startsWith(PingService.OGRS_SERVER_MSG));
>
> pingDao.verify();
> }
> }
>
> This test case uses MOCK for PingDAO, the interface of which is here:
> public interface PingDAO {
>
> /**
> * Gets the server date.
> * <at> return current date on the server.
> */
> public Timestamp getServerDate();
>
> /**
> * Saves specified <code>PingRequest</code>.
> * <at> param aPingRequest a ping request to be saved.
> */
> public void savePingRequest(PingRequest aPingRequest);
>
> /**
> * Deletes a ping request from the database using specified
> primary key.
> * <at> param aTimestamp Timestamp that uniquely identifies the ping
> request.
> */
> public void deletePingRequest(Timestamp aTimestamp);
>
> /**
> * Get the ping request using specified time stamp.
> * <at> param aTimestamp Timestamp that uniquely identifies the ping
> request.
> * <at> return <code>PingRequest</code> identified by the specified
> timestamp.
> */
> public PingRequest getPingRequest(Timestamp aTimestamp);
>
> }
>
> Thanks in advance for your time and help...
>
> Rajan
>
> ------------------------------------------------------------------------
> New Yahoo! Messenger with Voice. Call regular phones from your PC
>
<http://us.rd.yahoo.com/mail_us/taglines/postman5/*http://us.rd.yahoo.com/evt=39666/*http://beta.messenger.yahoo.com>
> and save big.
Thank you for a quick response David.
Could you please elaborate?
I use commons EqualBuilder to implement equals method.
The equals method looks like this:
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}
Thanks,
Rajan
David Saff <saff-3s7WtUTddSA@public.gmane.org> wrote:
Desai,
My first suspicion would be that PingRequest.equals is not what you want
it to be.
David Saff
Desai Rajan wrote:
> Hi all,
>
> I am new to JMock and have run in to this problem whose cause is
> unknown to me. Could some body help me debug this issue?
>
> I am getting an error:
> [junit] Testsuite: org.mediaslate.ogs.services.service.PingServiceTest
> [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.031 sec
> [junit] ------------- Standard Output ---------------
> [junit] In setPingDAO :: mockPingDAO
> [junit] In setPingDAO :: mockPingDAO
> [junit] ------------- ---------------- ---------------
> [junit] Testcase:
> testPingDatabase(org.mediaslate.ogs.services.service.PingServiceTest):
> FAILED
> [junit] mockPingDAO: no match found
> [junit] Invoked:
> org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>)
> [junit] Allowed:
> [junit] expected once: savePingRequest(
> same(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>) ), is void
> [junit] org.jmock.core.DynamicMockError: mockPingDAO: no match found
> [junit] Invoked:
> org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>)
> [junit] Allowed:
> [junit] expected once: savePingRequest(
> same(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>) ), is void
> [junit] at
> org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
> [junit] at org.jmock.core.CoreMock.invoke(Unknown Source)
> [junit] at $Proxy4.savePingRequest(Unknown Source)
> [junit] at
> org.mediaslate.ogs.se rvices.service.impl.PingServiceImpl.pingDatabase(PingServiceImpl.java:91)
> [junit] at
> org.mediaslate.ogs.services.service.PingServiceTest.testPingDatabase(PingServiceTest.java:46)
> [junit] at org.jmock.core.VerifyingTestCase.runBare(Unknown Source)
> [junit] TEST org.mediaslate.ogs.services.service.PingServiceTest
> FAILED
> [junit] Tests FAILED
>
> DAO definately has a method: public void savePingRequest(). What is
> causing JMock to thrown "No match found error" ?
>
> Here is my code:
>
> 1. Test case:
> public class PingServiceTest extends MockObjectTestCase {
> private PingService pingService = new PingServiceImpl();
> private Mock pingDao = null;
>
> protected void setUp() throws Exception {
> super.setUp();
>
> //Create a MOCK object for PingDAO.
> pingDao = new Moc k(PingDAO.class);
>
> //Set mock PingDAO for the ping service...
> pingService.setPingDAO((PingDAO)pingDao.proxy());
> }
>
> public void testPingApp() {
> String message = pingService.pingApp();
> assertEquals(message, PingService.OGRS_SERVER_MSG);
> }
>
> public void testPingDatabase() {
> Timestamp ts = new Timestamp(System.currentTimeMillis());
> PingRequest req = new PingRequest();
> req.setRequestTime(ts);
>
> pingDao.reset();
> pingDao.expects(once()).method("savePingRequest").
> with(same(req)).isVoid();
>
> String message = pingService.pingDatabase();
> assertTrue(message.startsWith(PingService.OGRS_SERVER_MSG));
>
> pingDao.verify();
> }
> }
>
> This test case uses MOCK for PingDAO, the interface of which is here:
> public interface PingDAO {
>
> /**
> * Gets the server date.
> * <at> return current date on the server.
> */
> public Timestamp getServerDate();
>
> /**
> * Saves specified PingRequest.
> * <at> param aPingRequest a ping request to be saved.
> */
> public void savePingRequest(PingRequest aPingRequest);
>
> /**
> * Deletes a ping request from the database using specified
> primary key.
> * <at> param aTimestamp Timestamp that uniquely identifies the ping
> request.
> */
> public void deletePingRequest(Timestamp aTimestamp);
>
> /**
> * Get the ping request using specified time stamp.
> * <at> param aTimestamp Timestamp that uniquely identifies the ping
> request.> * <at> return PingRequest identified by the specified
> timestamp.
> */
> public PingRequest getPingRequest(Timestamp aTimestamp);
>
> }
>
> Thanks in advance for your time and help...
>
> Rajan
>
> ------------------------------------------------------------------------
> New Yahoo! Messenger with Voice. Call regular phones from your PC
>
> and save big.
.mediaslate.ogs.services.model.PingRequest>.mediaslate.ogs.services.model.PingRequest>.mediaslate.ogs.services.model.PingRequest>.mediaslate.ogs.services.model.PingRequest>
How low will we go? Check out Yahoo! Messengers low PC-to-Phone call rates.
Desai,
The error message you saw means that there was no expectation set for
the actual method invocation seen. Since the method names match, the
arguments must be unequal, even though their toStrings appear to match.
Either equals is broken, or you're actually getting a different argument
than you expect. I don't know anything about CommonsBuilder, so I can't
comment on that. Good luck,
David Saff
> [junit] Invoked:
> org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>)
> [junit] Allowed:
> [junit] expected once: savePingRequest(
> same(
> [junit] requestTime=2006-04-05 14:58:31.078
> [junit] ]>) ), is void
Desai Rajan wrote:
> Thank you for a quick response David.
> Could you please elaborate?
>
> I use commons EqualBuilder to implement equals method.
>
> The equals method looks like this:
> public boolean equals(Object o) {
> return EqualsBuilder.reflectionEquals(this, o);
> }
>
> Thanks,
> Rajan
>
> */David Saff <saff@...>/* wrote:
>
> Desai,
>
> My first suspicion would be that PingRequest.equals is not what
> you want
> it to be.
>
> David Saff
>
> Desai Rajan wrote:
> > Hi all,
> >
> > I am new to JMock and have run in to this problem whose cause is
> > unknown to me. Could some body help me debug this issue?
> >
> > I am getting an error:
> > [junit] Testsuite:
> org.mediaslate.ogs.services.service.PingServiceTest
> > [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed:
> 0.031 sec
> > [junit] ------------- Standard Output ---------------
> > [junit] In setPingDAO :: mockPingDAO
> > [junit] In setPingDAO :: mockPingDAO
> > [junit] ------------- ---------------- ---------------
> > [junit] Testcase:
> >
> testPingDatabase(org.mediaslate.ogs.services.service.PingServiceTest):
>
> > FAILED
> > [junit] mockPingDAO: no match found
> > [junit] Invoked:
> > org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(
> > [junit] requestTime=2006-04-05 14:58:31.078
> > [junit] ]>)
> > [junit] Allowed:
> > [junit] expected once: savePingRequest(
> > same(
> > [junit] requestTime=2006-04-05 14:58:31.078
> > [junit] ]>) ), is void
> > [junit] org.jmock.core.DynamicMockError: mockPingDAO: no match found
> > [junit] Invoked:
> > org.mediaslate.ogs.services.dao.PingDAO.savePingRequest(
> > [junit] requestTime=2006-04-05 14:58:31.078
> > [junit] ]>)
> > [junit] Allowed:
> > [junit] expected once: savePingRequest(
> > same(
> > [junit] requestTime=2006-04-05 14:58:31.078
> > [junit] ]>) ), is void
> > [junit] at
> > org.jmock.core.AbstractDynamicMock.mockInvocation(Unknown Source)
> > [junit] at org.jmock.core.CoreMock.invoke(Unknown Source)
> > [junit] at $Proxy4.savePingRequest(Unknown Source)
> > [junit] at
> >
> org.mediaslate.ogs.services.service.impl.PingServiceImpl.pingDatabase(PingServiceImpl.java:91)
> > [junit] at
> >
> org.mediaslate.ogs.services.service.PingServiceTest.testPingDatabase(PingServiceTest.java:46)
> > [junit] at org.jmock.core.VerifyingTestCase.runBare(Unknown Source)
> > [junit] TEST org.mediaslate.ogs.services.service.PingServiceTest
> > FAILED
> > [junit] Tests FAILED
> >
> > DAO definately has a method: public void savePingRequest(). What is
> > causing JMock to thrown "No match found error" ?
> >
> > Here is my code:
> >
> > 1. Test case:
> > public class PingServiceTest extends MockObjectTestCase {
> > private PingService pingService = new PingServiceImpl();
> > private Mock pingDao = null;
> >
> > protected void setUp() throws Exception {
> > super.setUp();
> >
> > //Create a MOCK object for PingDAO.
> > pingDao = new Mock(PingDAO.class);
> >
> > //Set mock PingDAO for the ping service...
> > pingService.setPingDAO((PingDAO)pingDao.proxy());
> > }
> >
> > public void testPingApp() {
> > String message = pingService.pingApp();
> > assertEquals(message, PingService.OGRS_SERVER_MSG);
> > }
> >
> > public void testPingDatabase() {
> > Timestamp ts = new Timestamp(System.currentTimeMillis());
> > PingRequest req = new PingRequest();
> > req.setRequestTime(ts);
> >
> > pingDao.reset();
> > pingDao.expects(once()).method("savePingRequest").
> > with(same(req)).isVoid();
> >
> > String message = pingService.pingDatabase();
> > assertTrue(message.startsWith(PingService.OGRS_SERVER_MSG));
> >
> > pingDao.verify();
> > }
> > }
> >
> > This test case uses MOCK for PingDAO, the interface of which is
> here:
> > public interface PingDAO {
> >
> > /**
> > * Gets the server date.
> > * <at> return current date on the server.
> > */
> > public Timestamp getServerDate();
> >
> > /**
> > * Saves specified |PingRequest|.
> > * <at> param aPingRequest a ping request to be saved.
> > */
> > public void savePingRequest(PingRequest aPingRequest);
> >
> > /**
> > * Deletes a ping request from the database using specified
> > primary key.
> > * <at> param aTimestamp Timestamp that uniquely identifies the ping
> > request.
> > */
> > public void deletePingRequest(Timestamp aTimestamp);
> >
> > /**
> > * Get the ping request using specified time stamp.
> > * <at> param aTimestamp Timestamp that uniquely identifies the ping
> > request.
> > * <at> return |PingRequest| identified by the specified
> > timestamp.
> > */
> > public PingRequest getPingRequest(Timestamp aTimestamp);
> >
> > }
> >
> > Thanks in advance for your time and help...
> >
> > Rajan
> >
> >
> ------------------------------------------------------------------------
> > New Yahoo! Messenger with Voice. Call regular phones from your PC
> >
> > and save big.
>
>
> ------------------------------------------------------------------------
> How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone call
> rates.
> <http://us.rd.yahoo.com/mail_us/taglines/postman8/*http://us.rd.yahoo.com/evt=39663/*http://voice.yahoo.com>
RSS Feed2 | |
|---|---|
1 | |
5 | |
28 | |
1 | |
14 | |
2 | |
8 | |
8 | |
4 | |
3 | |
1 | |
18 | |
10 | |
15 | |
6 | |
8 | |
1 | |
1 | |
1 | |
7 | |
18 | |
20 | |
3 | |
6 | |
6 | |
4 | |
13 | |
15 | |
39 | |
23 | |
19 | |
15 | |
35 | |
24 | |
52 | |
41 | |
25 | |
13 | |
28 | |
50 | |
11 | |
19 | |
41 | |
80 | |
46 | |
44 | |
50 | |
69 | |
29 | |
85 | |
33 | |
48 | |
115 | |
82 | |
88 | |
83 | |
65 | |
37 | |
49 | |
30 | |
15 | |
20 | |
49 | |
69 | |
78 | |
103 | |
21 | |
78 | |
15 | |
80 | |
8 | |
24 | |
71 | |
38 |