FilesResultMapper { @NonNull public FilteredFilesResult transform(@Nullable ApiFilesResult apiFilesResult) { if (apiFilesResult == null) { return new FilteredFilesResult(Collections.<String>emptySet(), Collections.<String>emptySet()); } List<String> missingFilesRaw = new ArrayList<>(); if (apiFilesResult.getMissingFiles() != null ) { missingFilesRaw.addAll(apiFilesResult.getMissingFiles()); } if (apiFilesResult.getMissingUnknown() != null) { missingFilesRaw.addAll(apiFilesResult.getMissingUnknown()); } Set<String> missingFilenames = new HashSet<>(); for (String f: missingFilesRaw) { String filename = getFilenameFromPath(f); if (!isEmpty(filename)) { missingFilenames.add(filename); } } Set<String> deletedForms = new HashSet<>(); if (apiFilesResult.getDeletedForms() != null) { deletedForms.addAll(apiFilesResult.getDeletedForms()); } return new FilteredFilesResult(missingFilenames, deletedForms); } @Inject  FilesResultMapper(); @NonNull FilteredFilesResult transform(@Nullable ApiFilesResult apiFilesResult);  }
@Test public void transformShouldReturnBothMissingIfApiMissingUnKnownValues() { ApiFilesResult apiFilesResult = spy(new ApiFilesResult()); when(apiFilesResult.getMissingFiles()).thenReturn(Collections.singletonList("123")); when(apiFilesResult.getMissingUnknown()).thenReturn(Collections.singletonList("1234")); when(apiFilesResult.getDeletedForms()).thenReturn(Collections.emptyList()); FilteredFilesResult result = new FilesResultMapper().transform(apiFilesResult); assertEquals(2, result.getMissingFiles().size()); Iterator<String> iterator = result.getMissingFiles().iterator(); assertEquals("123", iterator.next()); assertEquals("1234", iterator.next()); }