FilePathCreator { public static FilePath create(String basePath, String rawPath) { String relativePath = removeSubstring(rawPath, basePath); String absolutePath = basePath + relativePath; return new LiteFilePath(absolutePath); } private  FilePathCreator(); static FilePath unknownFilePath(); static FilePath create(String basePath, String rawPath); static FilePath create(String absolutePath);  }
@Test public void returnsFilePath() { FilePath filePath = FilePathCreator.create("foo/bar/10MB.zip"); String expectedAbsolutePath = "foo/bar/10MB.zip"; assertThat(filePath).isEqualTo(new LiteFilePath(expectedAbsolutePath)); }
@Test public void returnsFilePath_whenAssetUrlOnlyContainsFileName() { String assetUrl = "10MB.zip"; FilePath filePath = FilePathCreator.create(BASE_PATH, assetUrl); String expectedAbsolutePath = "/data/data/com.novoda.downloadmanager.demo.simple/files/10MB.zip"; assertThat(filePath).isEqualTo(new LiteFilePath(expectedAbsolutePath)); }
@Test public void returnsFilePath_whenAssetUrlContainsSubdirectories() { String assetUrl = "foo/bar/10MB.zip"; FilePath filePath = FilePathCreator.create(BASE_PATH, assetUrl); String expectedAbsolutePath = "/data/data/com.novoda.downloadmanager.demo.simple/files/foo/bar/10MB.zip"; assertThat(filePath).isEqualTo(new LiteFilePath(expectedAbsolutePath)); }
@Test public void returnsFilePath_whenAssetUrlAlreadyContainsBasePath() { String assetUrl = BASE_PATH + "foo/bar/10MB.zip"; FilePath filePath = FilePathCreator.create(BASE_PATH, assetUrl); String expectedAbsolutePath = "/data/data/com.novoda.downloadmanager.demo.simple/files/foo/bar/10MB.zip"; assertThat(filePath).isEqualTo(new LiteFilePath(expectedAbsolutePath)); }