如何使用Mockito模拟Android Signature类equals()方法

时间:2015-08-11 10:46:17

标签: java android unit-testing mockito

我正在使用Signatureequlas()方法来比较我班级中的两个签名对象。

for (Signature allowedSignature : storedSignature) {
                if (allowedSignature.equals(signature)) {
                    return true;
                }
   }

我已经使用Mockito编写测试用例来测试上面的代码块。我需要模拟Signature类和equals()方法。

    Signature signature = PowerMockito.mock(Signature.class);
    when(signature.equals((Signature)notNull())).thenReturn(true);

所以我已经像上面提到的那样实现了,但我收到这样的错误,

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Misplaced argument matcher detected here:

You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
Mocking methods declared on non-public parent classes is not supported.

0 个答案:

没有答案