简体   繁体   中英

Java - Skip line of mocked s3Client class from a junit

I need to be able to skip over the s3Client line below when myMethod is executed from a junit. MyClass is NOT mocked, nor is myMethod:

MyClass {
    myMethod(String bucketName, String path) {

        // do stuff

        // skip below when mocked in junit
        s3Client.deleteObject(new DeleteObjectRequest(bucketName, path));

        // more stuff
    {
{

In the junit I have:

s3Client = mock(AmazonS3.class);
when(s3Client.deleteObject(any(DeleteObjectRequest.class))).thenReturn(null);

The "when" does not compile:

when(T) cannot be applied to void. reason: no instances of type variable T exist so that void conforms to T.

Again, I just need to skip this line when from a junit. Any solutions appreciated. Thank you.

this worked:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM