Search in sources :

Example 1 with Category

use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.

the class CardDaoTest method testGetCardsByCategory.

@SmallTest
@Test
public void testGetCardsByCategory() throws Exception {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    setupThreeCategories();
    Category filterCategory1 = categoryDao.createOrReturn("My category");
    // If category specified is null, return all cards up to limit
    List<Card> cards1 = cardDao.getCardsByCategory(null, false, 50);
    assertEquals(28, cards1.size());
    // No category specified but with limit
    List<Card> cards2 = cardDao.getCardsByCategory(null, false, 10);
    assertEquals(10, cards2.size());
    // Get by category
    List<Card> cards3 = cardDao.getCardsByCategory(filterCategory1, false, 50);
    assertEquals(3, cards3.size());
    // Get by category with limit
    List<Card> cards4 = cardDao.getCardsByCategory(filterCategory1, false, 2);
    assertEquals(2, cards4.size());
    // Random cards shouldn't affect number of cards to get
    List<Card> cards5 = cardDao.getCardsByCategory(filterCategory1, true, 50);
    assertEquals(3, cards5.size());
}
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 2 with Category

use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.

the class CardDaoTest method setupThreeCategories.

/*
     * Card with "My Category" in ID 2, 5, 8
     */
private void setupThreeCategories() throws SQLException {
    CardDao cardDao = helper.getCardDao();
    CategoryDao categoryDao = helper.getCategoryDao();
    Card c = cardDao.queryForId(2);
    Category ct = new Category();
    ct.setName("My category");
    categoryDao.create(ct);
    c.setCategory(ct);
    cardDao.update(c);
    c = cardDao.queryForId(5);
    c.setCategory(ct);
    cardDao.update(c);
    c = cardDao.queryForId(8);
    c.setCategory(ct);
    cardDao.update(c);
}
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)

Example 3 with Category

use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.

the class CardDaoTest method testGetScheduledCardCount.

@SmallTest
@Test
public void testGetScheduledCardCount() throws Exception {
    CardDao cardDao = helper.getCardDao();
    assertEquals(0L, cardDao.getScheduledCardCount(null));
    setupThreeCategories();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    assertEquals(0L, cardDao.getScheduledCardCount(ct));
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 4 with Category

use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.

the class CardDaoTest method testGetNewCardCount.

@SmallTest
@Test
public void testGetNewCardCount() throws Exception {
    CardDao cardDao = helper.getCardDao();
    assertEquals(28L, cardDao.getNewCardCount(null));
    setupThreeCategories();
    CategoryDao categoryDao = helper.getCategoryDao();
    List<Category> cts = categoryDao.queryForEq("name", "My category");
    Category ct = cts.get(0);
    assertEquals(3L, cardDao.getNewCardCount(ct));
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) CategoryDao(org.liberty.android.fantastischmemo.dao.CategoryDao) CardDao(org.liberty.android.fantastischmemo.dao.CardDao) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) AbstractExistingDBTest(org.liberty.android.fantastischmemo.test.AbstractExistingDBTest) SmallTest(android.support.test.filters.SmallTest)

Example 5 with Category

use of org.liberty.android.fantastischmemo.entity.Category in project AnyMemo by helloworld1.

the class CardDaoTest method testCreateCards.

@SmallTest
@Test
public void testCreateCards() throws Exception {
    CardDao cardDao = helper.getCardDao();
    Card c = new Card();
    c.setOrdinal(29);
    c.setCategory(new Category());
    c.setLearningData(new LearningData());
    Card c2 = new Card();
    c2.setOrdinal(30);
    c2.setCategory(new Category());
    c2.setLearningData(new LearningData());
    List<Card> cards = new ArrayList<Card>();
    cards.add(c);
    cards.add(c2);
    cardDao.createCards(cards);
    // Should create two new card
    assertEquals(30, cardDao.countOf());
    // The new card's id and ordinal should be correct
    assertEquals(29, (int) c.getId());
    assertEquals(29, (int) c.getOrdinal());
    assertEquals(30, (int) c2.getId());
    assertEquals(30, (int) c2.getOrdinal());
}
Also used : Category(org.liberty.android.fantastischmemo.entity.Category) ArrayList(java.util.ArrayList) LearningData(org.liberty.android.fantastischmemo.entity.LearningData) 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)

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