我有这样的方法
private byte[] getInternalMDPayload(String metaDataDirString)
{
byte[] data = new byte[16384];
try
{
final InputStream internalMetadataInputStream = this.getClass().getClassLoader()
.getResourceAsStream(metaDataDirString);
data = ByteStreams.toByteArray(internalMetadataInputStream);
byteString = ByteString.copyFrom(data);
} catch (IOException e)
{
dl.debug("Error occurred while loading the metadata file" + metaDataDirString);
}
}
有没有办法模仿这些物体?
目前,我使用@Mocked final Process mockProcess
来模拟输入流,无法找到如何模拟ByteString
和byte[]
。
答案 0 :(得分:1)
我会这样做:
Mockito
.when(ByteString.copyFrom(Mockito.<byte[]>any()))
.thenReturn(ByteString.copyFromUtf8("byteString was mocked"));