JMock noob with jmock DAO woes

View: New views
5 Messages — Rating Filter:   Alert me  

JMock noob with jmock DAO woes

by David Brown-48 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello jmock dev, gurus and mortals, I am a jmock noob. I was introduced to jmock via an appfuse web app. I have all of the app testcases working correctly except for the jmock testcases. I have been reading the jmock doco but I realize that I won't master jmock for some time. I have some Java DAO testcases that actually access the target DB with passing results. The jmock testing with a similare testcase and the same classes and methods fail. I don't want to exclude the jmock from my testcase harness just because I can't understand why the same testcases in realtime don't match up with the jmock test cases. Please advise, David.




******************************
org.jmock.core.DynamicMockError: mockBullmasterDAO: tried to return null value from method returning int
Invoked: mockBullmasterDAO.deleteByPrimaryKey(<1L>)

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

    http://xircles.codehaus.org/manage_email



Re: JMock noob with jmock DAO woes

by Steve Freeman-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not quite sure what's going on here, but don't panic.

> org.jmock.core.DynamicMockError: mockBullmasterDAO: tried to return  
> null value from method returning int
> Invoked: mockBullmasterDAO.deleteByPrimaryKey(<1L>)


what this says is that you're calling a method deleteByPrimaryKey()  
that should return an int, but that it's been set up to return a null.

In the expectations block, is there a line that looks like:

context.checking(new Expectations() {{
   one(mockBullmasterDAO).deleteByPrimaryKey(1);
}};


S

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627



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

    http://xircles.codehaus.org/manage_email



Parent Message unknown Re: JMock noob with jmock DAO woes

by David Brown-48 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Steve thanks for the speedy reply. The Expectations block and the whole JMock setup is more like the JMock 1 doco example:

mockDao = new Mock(BullmasterDAO.class);
bmgr.setBullmasterManagerDAO((BullmasterDAO) mockDao.proxy()); // bmgr: instance of bullmastermanager class

***** failing part ******
mockDao.expects(once()).method("deleteByPrimaryKey").with(eq(new Long(1)));
bmgr.deleteByPrimaryKey((long)1);
mockDao.verify(); // never gets here or not needed because of testcase error (not failure)




----- Original Message -----
From: "Steve Freeman" <steve@...>
To: user@...
Sent: Thursday, June 18, 2009 1:41:16 AM GMT -06:00 US/Canada Central
Subject: Re: [jmock-user] JMock noob with jmock DAO woes

Not quite sure what's going on here, but don't panic.

> org.jmock.core.DynamicMockError: mockBullmasterDAO: tried to return  
> null value from method returning int
> Invoked: mockBullmasterDAO.deleteByPrimaryKey(<1L>)


what this says is that you're calling a method deleteByPrimaryKey()  
that should return an int, but that it's been set up to return a null.

In the expectations block, is there a line that looks like:

context.checking(new Expectations() {{
   one(mockBullmasterDAO).deleteByPrimaryKey(1);
}};


S

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627



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

    http://xircles.codehaus.org/manage_email



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

    http://xircles.codehaus.org/manage_email



Re: JMock noob with jmock DAO woes

by Nat Pryce :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think you need to specify an int value to be returned from
deleteByPrimaryKey. Something like:

mockDao.expects(once()).method("deleteByPrimaryKey").with(eq(new Long(1)))
    .will(returnValue(1)); // or whatever the appropriate value is.

--Nat


2009/6/18 David Brown <dbrown@...>:

> Hello Steve thanks for the speedy reply. The Expectations block and the whole JMock setup is more like the JMock 1 doco example:
>
> mockDao = new Mock(BullmasterDAO.class);
> bmgr.setBullmasterManagerDAO((BullmasterDAO) mockDao.proxy()); // bmgr: instance of bullmastermanager class
>
> ***** failing part ******
> mockDao.expects(once()).method("deleteByPrimaryKey").with(eq(new Long(1)));
> bmgr.deleteByPrimaryKey((long)1);
> mockDao.verify(); // never gets here or not needed because of testcase error (not failure)
>
>
>
>
> ----- Original Message -----
> From: "Steve Freeman" <steve@...>
> To: user@...
> Sent: Thursday, June 18, 2009 1:41:16 AM GMT -06:00 US/Canada Central
> Subject: Re: [jmock-user] JMock noob with jmock DAO woes
>
> Not quite sure what's going on here, but don't panic.
>
>> org.jmock.core.DynamicMockError: mockBullmasterDAO: tried to return
>> null value from method returning int
>> Invoked: mockBullmasterDAO.deleteByPrimaryKey(<1L>)
>
>
> what this says is that you're calling a method deleteByPrimaryKey()
> that should return an int, but that it's been set up to return a null.
>
> In the expectations block, is there a line that looks like:
>
> context.checking(new Expectations() {{
>   one(mockBullmasterDAO).deleteByPrimaryKey(1);
> }};
>
>
> S
>
> Steve Freeman
> Winner of the Agile Alliance Gordon Pask award 2006
>
> http://www.m3p.co.uk
>
> M3P Limited.
> Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
> Company registered in England & Wales. Number 03689627
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>



--
http://www.natpryce.com

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

    http://xircles.codehaus.org/manage_email



Re: JMock noob with jmock DAO woes

by David Brown-48 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Nat, thanks for the speedy and informative reply. That worked. I found in the JMock 1 doco: http://www.jmock.org/jmock1-dispatch.html the foundation for your answer. I'm not sure I would have fixed this myself even with the doco find. I have yet another API to learn (YAATL). Thanks much, David.



----- Original Message -----
From: "Nat Pryce" <nat.pryce@...>
To: user@...
Sent: Friday, June 19, 2009 1:37:05 AM GMT -06:00 US/Canada Central
Subject: Re: [jmock-user] JMock noob with jmock DAO woes

I think you need to specify an int value to be returned from
deleteByPrimaryKey. Something like:

mockDao.expects(once()).method("deleteByPrimaryKey").with(eq(new Long(1)))
    .will(returnValue(1)); // or whatever the appropriate value is.

--Nat


2009/6/18 David Brown <dbrown@...>:

> Hello Steve thanks for the speedy reply. The Expectations block and the whole JMock setup is more like the JMock 1 doco example:
>
> mockDao = new Mock(BullmasterDAO.class);
> bmgr.setBullmasterManagerDAO((BullmasterDAO) mockDao.proxy()); // bmgr: instance of bullmastermanager class
>
> ***** failing part ******
> mockDao.expects(once()).method("deleteByPrimaryKey").with(eq(new Long(1)));
> bmgr.deleteByPrimaryKey((long)1);
> mockDao.verify(); // never gets here or not needed because of testcase error (not failure)
>
>
>
>
> ----- Original Message -----
> From: "Steve Freeman" <steve@...>
> To: user@...
> Sent: Thursday, June 18, 2009 1:41:16 AM GMT -06:00 US/Canada Central
> Subject: Re: [jmock-user] JMock noob with jmock DAO woes
>
> Not quite sure what's going on here, but don't panic.
>
>> org.jmock.core.DynamicMockError: mockBullmasterDAO: tried to return
>> null value from method returning int
>> Invoked: mockBullmasterDAO.deleteByPrimaryKey(<1L>)
>
>
> what this says is that you're calling a method deleteByPrimaryKey()
> that should return an int, but that it's been set up to return a null.
>
> In the expectations block, is there a line that looks like:
>
> context.checking(new Expectations() {{
>   one(mockBullmasterDAO).deleteByPrimaryKey(1);
> }};
>
>
> S
>
> Steve Freeman
> Winner of the Agile Alliance Gordon Pask award 2006
>
> http://www.m3p.co.uk
>
> M3P Limited.
> Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
> Company registered in England & Wales. Number 03689627
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>



--
http://www.natpryce.com

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

    http://xircles.codehaus.org/manage_email



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

    http://xircles.codehaus.org/manage_email