when(s3Client.listObjects(any(ListObjectsRequest.class))).thenAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args=invocationOnMock.getArguments();
ListObjectsRequest r=(ListObjectsRequest) args[0];
if(!"foo-bar".equals(r.getBucketName()))
throw new Exception("Bucket name was not correctly specified");
if(!(1==r.getMaxKeys()))
throw new Exception("More than one result was asked for");
boolean ok=false;
final List<S3ObjectSummary> out= Lists.newArrayList();
if("pathoDromic".equals(r.getPrefix())) {
out.add(new S3ObjectSummary());
ok=true;
}
if("way-out/".equals(r.getPrefix())) {
ok=true;
}
if(ok) {
return new ObjectListing() {
@Override
public List<S3ObjectSummary> getObjectSummaries() {
return out;
}
};
}
throw new Exception("An unrecognized path ["+r.getPrefix()+"] was given");
}
});
}