我想知道一个班级的方法。我想这个stubbed方法返回任何实现公共接口但不具体的接口类型。
例如:
public interface CommonType() {}
public class SubTypeOne implements CommonType {}
public class SubTypeTwo implements CommonType {}
public class SubTypeThree implements CommonType {}
public class SubTypeToNotReturn implements CommonType {}
when(object.methodToStub()).thenReturn( )
当我想要模拟返回任何一类时,我应该在thenReturn()
括号中加入什么:
CommonType
,SubTypeOne
,SubTypeTwo
,SubTypeThree
但不是SubTypeToNotReturn
我已经尝试过了:
when(object.methodToStub()).thenReturn(not(new SubTypeToNotReturn()))
但它不起作用。我收到一个错误:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: No matchers found for Not(?).