use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.
the class MnemosyneXMLImporterTest method verify.
@Override
protected void verify(String destFilePath) throws Exception {
AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
LearningDataDao learningDataDao = helper.getLearningDataDao();
List<Card> cards = cardDao.queryForAll();
List<Category> categories = categoryDao.queryForAll();
for (Card c : cards) {
categoryDao.refresh(c.getCategory());
learningDataDao.refresh(c.getLearningData());
}
assertEquals(11, cards.size());
assertEquals(2, categories.size());
assertEquals("q1", cards.get(0).getQuestion());
assertEquals("a1", cards.get(0).getAnswer());
assertEquals("<Standard>", cards.get(0).getCategory().getName());
assertEquals("q2", cards.get(1).getQuestion());
assertEquals("a2", cards.get(1).getAnswer());
assertEquals("<Standard>", cards.get(1).getCategory().getName());
assertEquals("q3", cards.get(2).getQuestion());
assertEquals("a3", cards.get(2).getAnswer());
assertEquals("<Standard>", cards.get(3).getCategory().getName());
assertNotNull(cards.get(3).getQuestion());
assertNotNull(cards.get(3).getAnswer());
assertEquals("<Standard>", cards.get(3).getCategory().getName());
} finally {
helper.close();
}
}
use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.
the class CardDaoTest method testQueryPrevCardWithCategory.
@SmallTest
@Test
public void testQueryPrevCardWithCategory() throws Exception {
setupThreeCategories();
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
List<Category> cts = categoryDao.queryForEq("name", "My category");
Category ct = cts.get(0);
Card c5 = cardDao.queryForId(5);
Card c2 = cardDao.queryPrevCard(c5, ct);
assertEquals(2, (int) c2.getId());
Card c8 = cardDao.queryPrevCard(c2, ct);
assertEquals(8, (int) c8.getId());
}
use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.
the class CategoryDaoImpl method createOrReturn.
public Category createOrReturn(String name) {
try {
QueryBuilder<Category, Integer> qb = queryBuilder();
PreparedQuery<Category> pq = qb.where().eq("name", name).prepare();
Category c = queryForFirst(pq);
// Do not create a new one if exists
if (c != null) {
return c;
}
Category nc = new Category();
nc.setName(name);
create(nc);
// Create new one and it should exist
c = queryForFirst(pq);
assert c != null : "Category creation failed. The query is still null!";
return c;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.
the class CsvImporterTest method verify.
@Override
protected void verify(String destFilePath) throws Exception {
AnyMemoDBOpenHelper helper = AnyMemoDBOpenHelperManager.getHelper(getContext(), destFilePath);
try {
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
List<Card> cards = cardDao.queryForAll();
List<Category> categories = categoryDao.queryForAll();
for (Card c : cards) {
categoryDao.refresh(c.getCategory());
}
assertEquals(4, cards.size());
assertEquals(3, categories.size());
assertEquals("Question1", cards.get(0).getQuestion());
assertEquals("Answer1", cards.get(0).getAnswer());
assertEquals("Category1", cards.get(0).getCategory().getName());
assertEquals("Question2", cards.get(1).getQuestion());
assertEquals("Answer2", cards.get(1).getAnswer());
assertEquals("Category1", cards.get(1).getCategory().getName());
assertEquals("Question3", cards.get(2).getQuestion());
assertEquals("Answer3", cards.get(2).getAnswer());
assertEquals("Category2", cards.get(2).getCategory().getName());
assertEquals("Question4", cards.get(3).getQuestion());
assertEquals("Answer4", cards.get(3).getAnswer());
assertEquals("", cards.get(3).getCategory().getName());
} finally {
helper.close();
}
}
use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.
the class ImportMergingTest method setUp.
@Before
public void setUp() throws Exception {
// Reflect out the test context
testContext = getContext();
amFileUtil = new AMFileUtil(testContext, new AMPrefUtil(getContext()));
newDbCardList = new ArrayList<Card>();
Card c1 = new Card();
c1.setQuestion("old question 1");
c1.setAnswer("old answer 1");
c1.setLearningData(new LearningData());
c1.setCategory(new Category());
Card c2 = new Card();
c2.setQuestion("old question 2");
c2.setAnswer("old answer 2");
c2.setLearningData(new LearningData());
c2.setCategory(new Category());
newDbCardList.add(c1);
newDbCardList.add(c2);
}
Aggregations