AssetsHelper { public String makeSafeCopy(String pathToAsset) throws IOException { String assetName = FilenameUtils.getBaseName(pathToAsset); String assetExtension = mapExtension(FilenameUtils.getExtension(pathToAsset)); String safeCopyName = assetName + SEPARATOR + getRandomValue() + EXTENSION_SEPARATOR + assetExtension; File safeCopy = new File(context.getFilesDir(), safeCopyName); FileUtils.copyFile(new File(pathToAsset), safeCopy); return safeCopy.getName(); } AssetsHelper(Context context); String makeSafeCopy(String pathToAsset); String getFileFullPath(Asset asset);  }
@Test public void whenMakingSafeCopyJPEGExpectNewFilePathBeReturned() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpegFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(safeCopyName, matchesPattern(jpgFileSafeCopyNamePattern)); }
@Test public void whenMakingSafeCopyPNGExpectNewFilePathBeReturned() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(pngFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(safeCopyName, matchesPattern(pngFileSafeCopyNamePattern)); }
@Test public void whenMakingSafeCopyExpectFileCopyHasBeenCreated() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpgFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(new File(pathToInternalStorage, safeCopyName).exists(), is(true)); }
@Test public void whenMakingSafeCopyJPEGExpectFileCopyHasBeenCreated() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpegFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(new File(pathToInternalStorage, safeCopyName).exists(), is(true)); }
@Test public void whenMakingSafeCopyPNGExpectFileCopyHasBeenCreated() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(pngFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(new File(pathToInternalStorage, safeCopyName).exists(), is(true)); }
@Test public void whenMakingSafeCopyExpectEachFilePathBeDifferent() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpgFile.getAbsolutePath()); String secondSafeCopyName = assetsHelper.makeSafeCopy(jpgFile.getAbsolutePath()); addToTestFiles(safeCopyName); addToTestFiles(secondSafeCopyName); assertThat(safeCopyName, is(not(equalTo(secondSafeCopyName)))); }
@Test public void whenMakingSafeCopyExpectNewFilePathBeReturned() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpgFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(safeCopyName, matchesPattern(jpgFileSafeCopyNamePattern)); }
@Test public void whenMakingSafeCopyJPGExpectNewFilePathBeReturned() throws IOException { String safeCopyName = assetsHelper.makeSafeCopy(jpgUpperFile.getAbsolutePath()); addToTestFiles(safeCopyName); assertThat(safeCopyName, matchesPattern(jpgFileSafeCopyNamePattern)); }