我正在尝试使用超级模拟来模拟最终类,但是得到“无法模拟/间谍类com.microsoft.azure.storage.blob.CloudBlockBlob \ nMockito无法模拟/间谍,因为:\ n-最终类”如下我正在尝试的代码
@RunWith(PowerMockRunner.class)
@PrepareForTest({CloudBlockBlob.class})
@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
public class Test {
@org.junit.jupiter.api.Test
public void test() throws IOException, StorageException {
CloudBlockBlob cloudBlockBlob = PowerMockito.mock(CloudBlockBlob.class);
when(cloudBlockBlob.downloadText()).thenReturn("hello");
}
}
和gradle依赖项如下:
testCompile group: 'junit', name: 'junit', version: '4.13'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.7'