1

我正在使用 jMock,我对如何模拟我想成为任何 entityClass 的参数感到困惑?

这是我要匹配的方法:

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

这是我得到的。我想匹配第二个参数上的任何内容:

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

这不起作用,因为我在第一个参数上使用了 with。无论存在什么参数,我基本上都想模拟这种方法。

4

2 回答 2

1

我改用忽略方法来满足我的需求:

ignoring(myTemplate);
于 2011-09-19T15:57:40.960 回答
1

如果您只想忽略模拟对象中的一种方法,您还可以编写:

allowing(template).find(with(any(Query.class)), with(any(Class.class))); 
于 2013-01-18T01:18:06.067 回答