### Question:
S3FileList { protected List<String> lastFilesPerBillingPeriod(List<S3ObjectSummary> objectSummaries) { final Map<String, List<S3ObjectSummary>> months = objectSummaries.stream() .collect(Collectors.groupingBy(o -> extractDatePrefix(reportPattern, o), mapping(o -> o, toList()))); return months.entrySet() .stream() .flatMap(this::lastFileForBillingPeriod) .sorted() .collect(Collectors.toList()); } S3FileList(boolean awsJobEnabled, String bucket, ModuleData moduleData); List<String> getFiles(AmazonS3 s3Client);  }### Answer:
@Test public void testGettingLastFilesInBillingPeriod() throws Exception { final ListObjectsV2Result result = mock(ListObjectsV2Result.class); final ModuleData moduleData = mock(ModuleData.class); final List<S3ObjectSummary> objectSummaries = Arrays.asList( getObjectSummary("DLAB-billing/reportName/20180101-20180201/guid1/test-1.csv.zip", LocalDate.of(2018, 4, 1)), getObjectSummary("DLAB-billing/reportName/20180101-20180201/guid1/test-2.csv.zip", LocalDate.of(2018, 4, 1)), getObjectSummary("DLAB-billing/reportName/20180101-20180201/guid0/test-1.csv.zip", LocalDate.of(2018, 1, 1)), getObjectSummary("DLAB-billing/reportName/20180201-20180301/guid0/test-1.csv.zip", LocalDate.of(2018, 1, 1)), getObjectSummary("DLAB-billing/reportName/20180202-20180301/guid0/test-2.csv.zip", LocalDate.of(2018, 1, 1)) ); when(result.getObjectSummaries()).thenReturn(objectSummaries); final List<String> files = new S3FileList(true, null, moduleData).lastFilesPerBillingPeriod(result .getObjectSummaries()); assertEquals(4, files.size()); assertTrue(files.contains("DLAB-billing/reportName/20180101-20180201/guid1/test-1.csv.zip")); assertTrue(files.contains("DLAB-billing/reportName/20180101-20180201/guid1/test-2.csv.zip")); assertTrue(files.contains("DLAB-billing/reportName/20180201-20180301/guid0/test-1.csv.zip")); assertTrue(files.contains("DLAB-billing/reportName/20180202-20180301/guid0/test-2.csv.zip")); }