I am trying to mock the following line:
for (S3ObjectSummary objectSummary : S3Objects.withPrefix(s3, s3URI.getBucket(), s3URI.getKey())) {
// some code
}
How do I go about mocking S3Objects.withPrefix? As per AWS documentation, the return type of this function is a static S3Objects (which is basically an iterable over a bucket).
I currently try to mock it using the following code:
@RunWith(PowerMockRunner.class)
@PrepareForTest({S3Objects.class})
public class TestMyMethod extends TestBase {
public void setup() {
// setup other stuff and mock them
PowerMockito.mockStatic(S3Objects.class);
Mockito.when(S3Objects.withPrefix(any(), any(), any())).thenReturn(any(S3Objects.class));
//continue setting up other stuff
}