0

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.

Timothy Clotworthy
  • 1,960
  • 2
  • 19
  • 42

1 Answers1

0

this worked:

doNothing().when(s3Client).deleteObject(any(DeleteObjectRequest.class));
Timothy Clotworthy
  • 1,960
  • 2
  • 19
  • 42