### Question:
S3Client { boolean isEmpty(String bucket, String key, String leafKey) { List<S3ObjectSummary> objectsLeftAtPath = amazonS3.listObjectsV2(bucket, key + "/").getObjectSummaries(); if (!dryRunEnabled) { return objectsLeftAtPath.size() == 0; } else { String leafKeySentinel = leafKey + S3SentinelFilesCleaner.SENTINEL_SUFFIX; for (S3ObjectSummary s3ObjectSummary : objectsLeftAtPath) { String currentKey = s3ObjectSummary.getKey(); if (!currentKey.startsWith(leafKey + "/") && !currentKey.equals(leafKeySentinel)) { return false; } } return true; } } S3Client(AmazonS3 amazonS3, boolean dryRunEnabled);   }### Answer:
@Test void isEmptyForNonEmptyDirectory() { amazonS3.putObject(bucket, key1, content); boolean result = s3Client.isEmpty(bucket, keyRoot, null); assertThat(result).isFalse(); }
@Test void isEmptyForNonEmptyDirectoryWithSpacedKey() { String spacedKey = key1 + "/ /file"; amazonS3.putObject(bucket, spacedKey, content); boolean result = s3Client.isEmpty(bucket, keyRoot, null); assertThat(result).isFalse(); }
@Test void isEmptyForEmptyDirectory() { boolean result = s3Client.isEmpty(bucket, keyRoot, null); assertThat(result).isTrue(); }
@Test void isEmptyDryRunForNonEmptyDirectoryAndCorrectLeafKey() { amazonS3.putObject(bucket, key1, content); boolean result = s3ClientDryRun.isEmpty(bucket, "table", keyRoot); assertThat(result).isTrue(); }
@Test void isEmptyDryRunForEmptyDirectory() { boolean result = s3ClientDryRun.isEmpty(bucket, "table", keyRoot); assertThat(result).isTrue(); }
@Test void isEmptyDryRunForOtherHighLevelDirectory() { amazonS3.putObject(bucket, "table/partition_2", content); boolean result = s3ClientDryRun.isEmpty(bucket, "table", keyRoot); assertThat(result).isFalse(); }
@Test void isEmptyDryRunForCommonFolderName() { String otherPartition = "table/test/test/partition10"; String folder1 = "table"; String folder2 = "table/test"; String folder3 = "table/test/test"; String folder4 = "table/test/test/partition1"; String filePath = "table/test/test/partition1/test"; String sentinel1 = "table_$folder$"; String sentinel2 = "table/test_$folder$"; String sentinel3 = "table/test/test_$folder$"; String sentinel4 = "table/test/test/partition1_$folder$"; amazonS3.putObject(bucket, filePath, content); amazonS3.putObject(bucket, sentinel1, ""); amazonS3.putObject(bucket, sentinel2, ""); amazonS3.putObject(bucket, sentinel3, ""); amazonS3.putObject(bucket, sentinel4, ""); assertThat(s3ClientDryRun.isEmpty(bucket, folder3, folder4)).isTrue(); assertThat(s3ClientDryRun.isEmpty(bucket, folder3, otherPartition)).isFalse(); assertThat(s3ClientDryRun.isEmpty(bucket, folder2, folder3)).isTrue(); assertThat(s3ClientDryRun.isEmpty(bucket, folder1, folder2)).isTrue(); }