Java -跳过junit中模拟的s3 Client类的行

fivyi3re  于 2023-01-24  发布在  Java
关注(0)|答案(1)|浏览(119)

当myMethod从junit执行时,我需要跳过下面的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。任何解决方案赞赏。谢谢。

fkaflof6

fkaflof61#

这起了作用:

doNothing().when(s3Client).deleteObject(any(DeleteObjectRequest.class));

相关问题