【发布时间】:2023-01-23 23:40:09
【问题描述】:
当从 junit 执行 myMethod 时,我需要能够跳过下面的 s3Client 行。 MyClass 没有被模拟,myMethod 也没有:
MyClass {
myMethod(String bucketName, String path) {
// do stuff
// skip below when mocked in junit
s3Client.deleteObject(new DeleteObjectRequest(bucketName, path));
// more stuff
{
{
在 junit 我有:
s3Client = mock(AmazonS3.class);
when(s3Client.deleteObject(any(DeleteObjectRequest.class))).thenReturn(null);
“when”不编译:
when(T) cannot be applied to void. reason: no instances of type variable T exist so that void conforms to T.
同样,我只需要从 junit 跳过这一行。任何解决方案表示赞赏。谢谢你。
【问题讨论】:
-
deleteObjectsvsdeleteObject就像错误消息所说的那样? -
@DaveNewton 感谢捕获。现在仍然错误但不同。更新帖子
标签: java mockito knox-amazon-s3-client