Boiler Bill
Boiler Bill

Reputation: 1960

Using JMock how do I mock an argument of Class<T>?

I am using jMock and I am confused as to how to mock an argument that I want to be any entityClass?

Here is the method I am trying to match:

public <T> List<T> find(Query query, Class<T> entityClass) { }

Here is what I got. I want to match anything on the second parameter:

allowing(template).find(with(any(Query.class)), Foo.class);

which doesn't work since I used with on the first parameter. I basically want to mock this method no matter what arguments are present.

Upvotes: 1

Views: 1100

Answers (2)

AdrianRM
AdrianRM

Reputation: 2771

If you only want to ignore that one method in your mock object, you could also write:

allowing(template).find(with(any(Query.class)), with(any(Class.class))); 

Upvotes: 1

Boiler Bill
Boiler Bill

Reputation: 1960

I switched to using the ignoring method to meet my needs:

ignoring(myTemplate);

Upvotes: 1

Related Questions