use of org.liberty.android.fantastischmemo.converter.QATxtImporter in project AnyMemo by helloworld1.
the class ImportMergingTest method testMergeQATxtIntoDb.
@SmallTest
@Test
public void testMergeQATxtIntoDb() throws Exception {
srcFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.txt";
destFilePath = AMEnv.DEFAULT_ROOT_PATH + "/" + "qa-text-test.db";
new File(srcFilePath).delete();
new File(destFilePath).delete();
AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
// Create an new db with some contents
helper.getCardDao().createCards(newDbCardList);
} finally {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
amFileUtil.copyFileFromAsset("qa-text-test.txt", new File(srcFilePath));
Converter converter = new QATxtImporter(amFileUtil);
converter.convert(srcFilePath, destFilePath);
helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
List<Card> cards = helper.getCardDao().getAllCards(null);
assertEquals(4, cards.size());
assertEquals(1, (int) cards.get(0).getId());
assertEquals(1, (int) cards.get(0).getOrdinal());
assertEquals("old question 1", cards.get(0).getQuestion());
assertEquals("old answer 1", cards.get(0).getAnswer());
assertEquals(2, (int) cards.get(1).getId());
assertEquals(2, (int) cards.get(1).getOrdinal());
assertEquals("old question 2", cards.get(1).getQuestion());
assertEquals("old answer 2", cards.get(1).getAnswer());
assertEquals(3, (int) cards.get(2).getId());
assertEquals(3, (int) cards.get(2).getOrdinal());
assertEquals("This is question1", cards.get(2).getQuestion());
assertEquals("Answer1", cards.get(2).getAnswer());
assertEquals(4, (int) cards.get(3).getId());
assertEquals(4, (int) cards.get(3).getOrdinal());
assertEquals("Question2", cards.get(3).getQuestion());
assertEquals("Answer2", cards.get(3).getAnswer());
} finally {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
}
Aggregations