1
votes

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.

2

2 Answers

1
votes

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

ignoring(myTemplate);
1
votes

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)));