### Question:
S3FileSystemProvider implements FileSystemProvider { @Nonnull @Override public List<DataSetFile> listFiles(@Nonnull final Path path, @Nonnull final Configuration conf) { final AmazonS3 s3; final URI uri = path.toUri(); if ("s3".equalsIgnoreCase(uri.getScheme()) || "s3bfs".equalsIgnoreCase(uri.getScheme()) || "s3n".equalsIgnoreCase(uri.getScheme())) { s3 = createS3Client(uri, conf); } else if ("s3a".equalsIgnoreCase(uri.getScheme())) { final Class<? extends S3ClientFactory> s3ClientFactoryClass = conf.getClass(Constants.S3_CLIENT_FACTORY_IMPL, Constants.DEFAULT_S3_CLIENT_FACTORY_IMPL, S3ClientFactory.class); try { s3 = ReflectionUtils.newInstance(s3ClientFactoryClass, conf).createS3Client(uri); } catch (final IOException e) { throw new IllegalArgumentException("Unable to create S3 client: " + e, e); } } else { log.debug("Scheme {} not supported for S3 path: {}", uri.getScheme(), path); throw new CatalogException("catalog.fs.s3.invalidScheme", uri.getScheme()); } try { return s3.listBuckets().stream() .map(bucket -> { final DataSetFile file = new DataSetFile(); file.setName(bucket.getName()); file.setDirectory(true); file.setModificationTime(bucket.getCreationDate().getTime()); file.setPath(uri.getScheme() + ": return file; }) .collect(Collectors.toList()); } finally { s3.shutdown(); } }  @Nonnull @Override List<DataSetFile> listFiles(@Nonnull final Path path, @Nonnull final Configuration conf); @Override boolean supportsPath(@Nonnull final Path path);  }### Answer:
@Test @SuppressWarnings("unchecked") public void listFilesS3a() { final Configuration conf = new Configuration(false); conf.setClass(Constants.S3_CLIENT_FACTORY_IMPL, MockS3ClientFactory.class, S3ClientFactory.class); final S3FileSystemProvider provider = new S3FileSystemProvider(); final List<DataSetFile> files = provider.listFiles(new Path(S3A), conf); Assert.assertThat(files, CoreMatchers.hasItems(isDataSetFile(MockS3ClientFactory.BUCKET1), isDataSetFile(MockS3ClientFactory.BUCKET2))); Assert.assertEquals(2, files.size()); }
@Test @SuppressWarnings("unchecked") public void listFilesS3n() { final AmazonS3 client = Mockito.mock(AmazonS3.class); final Bucket bucket1 = AmazonS3Util.createBucket("bucket1"); final Bucket bucket2 = AmazonS3Util.createBucket("bucket2"); Mockito.when(client.listBuckets()).thenReturn(Arrays.asList(bucket1, bucket2)); final S3FileSystemProvider provider = new S3FileSystemProvider() { @Override protected AmazonS3 createS3Client(@Nonnull final URI uri, @Nonnull final Configuration conf) { return client; } }; final List<DataSetFile> files = provider.listFiles(new Path(S3N), new Configuration(false)); Assert.assertThat(files, CoreMatchers.hasItems(isDataSetFile(bucket1), isDataSetFile(bucket2))); Assert.assertEquals(2, files.size()); }