You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gmock-user
Hi,
I'm trying to mock the java.nio.ByteBuffer class. Just as a quick
example:
// test code
buf = gmc.mock(ByteBuffer)
gmc.ordered {
buf.get().returns(0x1e) // this line works
buf.position().returns(1) // this line does not
buf.capacity().returns(1) // this line does not
}
// code under test
byte b = bb.get();
System.out.println(b);
System.out.println(bb.position());
System.out.println(bb.capacity());
// output
30
0
0
The main difference I see between the 3 methods are that the latter 2,
position and capacity, are final. Is it possible to mock these calls
with gmock?
Thanks,
David
Johnny
unread,
Apr 13, 2009, 9:41:21 PM4/13/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gmock...@googlegroups.com
Hi David,
Unfortunately, gmock cannot mock final methods or final classes on the
Java side (but can do so on the Groovy side), neither do easymock and
jmock.
Johnny
在 2009-04-13一的 15:33 -0700,david写道:
Julien Gagnet
unread,
Apr 14, 2009, 2:31:43 AM4/14/09
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to gmock...@googlegroups.com
Johnny is right about about final classes. However if you can live
without the strong typing it should work:
def buf = gmc.mock()
gmc.ordered {
buf.get().returns(0x1e) // this line works
buf.position().returns(1) // this line does not
buf.capacity().returns(1) // this line does not
}