EasyMock: Wrong number of arguments

J

Janwillem Borleffs

Hello,

I want to partially mock a public class implementation. I'm mocking two
methods and call an unmocked third one, which calls upon the first two.

All's well, and the unittests succeed as expected. But I keep getting
annoying "wrong number of arguments" log messages thrown by the Reflection
API which is used in the background by EasyMock classextensions.

The code I'm using drills down to this:

// start code

Method[] methods = {
Object2Mock.class.getMethod("method1", String.class),
Object2Mock.class.getMethod("method2") // No arguments
};

Object2Mock object2mock = createMock(Object2Mock.class, methods);

expect(object2mock.method1("foo")).andReturn("bar");
expect(object2mock.method2()).andReturn("baz");
replay(object2mock);

object2mock.method3();

verify(object2mock);

// end code

I've also tried to pass the ConstructorArgs argument to the createMock()
method, to no avail. Please note that the usual way of handling these
situations (create an instance and pass the mocked object through one of the
instance methods) doesn't apply here, due to the class design.

I would appreciate any pointers.

TIA & Regards,
JW
 
R

Roedy Green

I want to partially mock a public class implementation.

I have never heard this term before. What does it mean in this
context? In ordinary English it means "viciously make fun of" or
"make a replica".
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Everybody’s worried about stopping terrorism. Well, there’s a really easy way: stop participating in it."
~ Noam Chomsky
 
M

Mark Space

Roedy said:
I have never heard this term before. What does it mean in this
context? In ordinary English it means "viciously make fun of" or
"make a replica".


The latter. EasyMock has a web site. A quite read through of the front
page will answer your questions.

Basically a "mock" object is an object with instantiates an interface
and is used to unit test another object which uses that interface.
 
J

Janwillem Borleffs

Mark Space schreef:
The latter. EasyMock has a web site. A quite read through of the front
page will answer your questions.

Basically a "mock" object is an object with instantiates an interface
and is used to unit test another object which uses that interface.

I've used this description to point out I'm not mocking an abstract
class nor an interface.


JW
 
J

Janwillem Borleffs

Janwillem Borleffs schreef:
I would appreciate any pointers.

Solved!

The problem was that in the partially mocked class, I used a convenience
method from another package, which also uses the Reflection API to
transfer data between objects; one of these objects was an instance of
the class being mocked.

Once I removed the call, the error message was gone.

JW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top