MigrationPathExtractor { static FilePath extractMigrationPath(String basePath, String assetPath, DownloadBatchId downloadBatchId) { String relativePath = extractRelativePath(basePath, assetPath); String relativePathWithBatchId = prependBatchIdTo(relativePath, downloadBatchId); String fileName = extractFileName(assetPath); String absolutePath = basePath + PATH_SEPARATOR + relativePathWithBatchId + fileName; String sanitizedAbsolutePath = absolutePath.replaceAll(" return FilePathCreator.create(sanitizedAbsolutePath); } private  MigrationPathExtractor();   }
@Test public void returnsAbsolutePathAndFileName_whenAssetPathConsistsOfFileNameOnly() { String assetUrl = "/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/thechase.dat"; FilePath migrationPath = MigrationPathExtractor.extractMigrationPath(BASE_PATH, assetUrl, DOWNLOAD_BATCH_ID); assertThat(migrationPath.path()).isEqualTo("/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/batch_01/thechase.dat"); }
@Test public void returnsAbsolutePathAndFileName_whenAssetPathContainsSingleSubdirectory() { String assetUrl = "/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/foo/thechase.dat"; FilePath migrationPath = MigrationPathExtractor.extractMigrationPath(BASE_PATH, assetUrl, DOWNLOAD_BATCH_ID); assertThat(migrationPath.path()).isEqualTo("/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/batch_01/foo/thechase.dat"); }
@Test public void returnsAbsolutePathAndFileName_whenAssetPathContainsMultipleSubdirectories() { String assetUrl = "/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/foo/bar/thechase.dat"; FilePath migrationPath = MigrationPathExtractor.extractMigrationPath(BASE_PATH, assetUrl, DOWNLOAD_BATCH_ID); assertThat(migrationPath.path()).isEqualTo("/data/data/com.novoda.downloadmanager.demo.simple/files/Pictures/batch_01/foo/bar/thechase.dat"); }