Search in sources :

Example 16 with Category

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();
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) LearningDataDao(org.liberty.android.fantastischmemo.dao.LearningDataDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 17 with Category

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());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 18 with Category

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);
    }
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) SQLException(java.sql.SQLException)

Example 19 with Category

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();
    }
}
Also used : AnyMemoDBOpenHelper(org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper) Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Card(org.liberty.android.fantastischmemo.entity.Card)

Example 20 with Category

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);
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) AMFileUtil(org.liberty.android.fantastischmemo.utils.AMFileUtil) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) AMPrefUtil(org.liberty.android.fantastischmemo.utils.AMPrefUtil) Card(org.liberty.android.fantastischmemo.entity.Card) Before(org.junit.Before)

Aggregations

Category (org.liberty.android.fantastischmemo.entity.Category)35 Card (org.liberty.android.fantastischmemo.entity.Card)30 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)27 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)19 SmallTest (android.support.test.filters.SmallTest)17 Test (org.junit.Test)17 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)17 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)15 AnyMemoDBOpenHelper (org.liberty.android.fantastischmemo.common.AnyMemoDBOpenHelper)11 LearningDataDao (org.liberty.android.fantastischmemo.dao.LearningDataDao)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 LinkedList (java.util.LinkedList)2 QueueManager (org.liberty.android.fantastischmemo.queue.QueueManager)2 Intent (android.content.Intent)1