use of com.ichi2.anki.exception.ImportExportException in project Anki-Android by ankidroid.
the class AnkiPackageExporterTest method fileInExportIsCopied.
@Test
public void fileInExportIsCopied() throws IOException, ImportExportException {
// Arrange
File tempFileInCollection = addTempFileToMediaAndNote();
AnkiPackageExporter exporter = getExporterForDeckWithMedia();
File temp = CreateTempDir.tempDir("/AnkiDroid-missingFileInExportDoesNotThrowException-export");
File exportedFile = new File(temp.getAbsolutePath() + "/export.apkg");
// Exporting
exporter.exportInto(exportedFile.getAbsolutePath(), getTargetContext());
// Unzipping the export.apkg file
UnzipFile.unzip(exportedFile, temp.getAbsolutePath() + "/unzipped");
String unzipDirectory = temp.getAbsolutePath() + "/unzipped";
// Storing paths of unzipped files in a list
List<String> files = Arrays.asList(new File(unzipDirectory).list());
File[] fileNames = new File[3];
int i = 0;
for (String x : files) {
File f = new File(unzipDirectory + "/" + x);
fileNames[i++] = f;
}
// Checking the unzipped files
assertThat(files, containsInAnyOrder("collection.anki2", "media", "0"));
assertThat("Three files should exist", files, hasSize(3));
// {"0":"filename.txt"}
String expected = String.format("{\"0\":\"%s\"}", tempFileInCollection.getName());
checkMediaExportStringIs(fileNames, expected);
}
Aggregations