|
|
@ -7,7 +7,6 @@ package com.todoroo.astrid.dao;
|
|
|
|
|
|
|
|
|
|
|
|
import android.support.test.runner.AndroidJUnit4;
|
|
|
|
import android.support.test.runner.AndroidJUnit4;
|
|
|
|
|
|
|
|
|
|
|
|
import com.todoroo.andlib.data.Property;
|
|
|
|
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
import com.todoroo.andlib.sql.Query;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
|
|
|
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
|
|
|
@ -21,19 +20,12 @@ import org.tasks.injection.TestComponent;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
|
|
import static junit.framework.Assert.assertEquals;
|
|
|
|
import static junit.framework.Assert.assertEquals;
|
|
|
|
import static junit.framework.Assert.assertFalse;
|
|
|
|
|
|
|
|
import static junit.framework.Assert.assertNotSame;
|
|
|
|
import static junit.framework.Assert.assertNotSame;
|
|
|
|
import static junit.framework.Assert.assertNull;
|
|
|
|
import static junit.framework.Assert.assertNull;
|
|
|
|
import static junit.framework.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4.class)
|
|
|
|
@RunWith(AndroidJUnit4.class)
|
|
|
|
public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
public static Property<?>[] IDS = new Property<?>[] { Task.ID };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static Property<?>[] TITLES = new Property<?>[] { Task.ID,
|
|
|
|
|
|
|
|
Task.TITLE };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject TaskDao taskDao;
|
|
|
|
@Inject TaskDao taskDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -41,13 +33,13 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testTaskCreation() {
|
|
|
|
public void testTaskCreation() {
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
// create task "happy"
|
|
|
|
// create task "happy"
|
|
|
|
Task task = new Task();
|
|
|
|
Task task = new Task();
|
|
|
|
task.setTitle("happy");
|
|
|
|
task.setTitle("happy");
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
assertEquals(1, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(1, taskDao.toList(Query.select()).size());
|
|
|
|
long happyId = task.getId();
|
|
|
|
long happyId = task.getId();
|
|
|
|
assertNotSame(Task.NO_ID, happyId);
|
|
|
|
assertNotSame(Task.NO_ID, happyId);
|
|
|
|
task = taskDao.fetch(happyId);
|
|
|
|
task = taskDao.fetch(happyId);
|
|
|
@ -57,14 +49,14 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
task = new Task();
|
|
|
|
task = new Task();
|
|
|
|
task.setTitle("sad");
|
|
|
|
task.setTitle("sad");
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
assertEquals(2, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(2, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
// rename sad to melancholy
|
|
|
|
// rename sad to melancholy
|
|
|
|
long sadId = task.getId();
|
|
|
|
long sadId = task.getId();
|
|
|
|
assertNotSame(Task.NO_ID, sadId);
|
|
|
|
assertNotSame(Task.NO_ID, sadId);
|
|
|
|
task.setTitle("melancholy");
|
|
|
|
task.setTitle("melancholy");
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
assertEquals(2, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(2, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
// check state
|
|
|
|
// check state
|
|
|
|
task = taskDao.fetch(happyId);
|
|
|
|
task = taskDao.fetch(happyId);
|
|
|
@ -112,10 +104,10 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
|
|
|
|
|
|
|
|
// check is active
|
|
|
|
// check is active
|
|
|
|
assertEquals(5, taskDao.toList(Query.select(TITLES).where(TaskCriteria.isActive())).size());
|
|
|
|
assertEquals(5, taskDao.toList(Query.select().where(TaskCriteria.isActive())).size());
|
|
|
|
|
|
|
|
|
|
|
|
// check is visible
|
|
|
|
// check is visible
|
|
|
|
assertEquals(5, taskDao.toList(Query.select(TITLES).where(TaskCriteria.isVisible())).size());
|
|
|
|
assertEquals(5, taskDao.toList(Query.select().where(TaskCriteria.isVisible())).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -123,18 +115,18 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testTDeletion() {
|
|
|
|
public void testTDeletion() {
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
// create task "happy"
|
|
|
|
// create task "happy"
|
|
|
|
Task task = new Task();
|
|
|
|
Task task = new Task();
|
|
|
|
task.setTitle("happy");
|
|
|
|
task.setTitle("happy");
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
assertEquals(1, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(1, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
// delete
|
|
|
|
// delete
|
|
|
|
long happyId = task.getId();
|
|
|
|
long happyId = task.getId();
|
|
|
|
assertEquals(1, taskDao.deleteById(happyId));
|
|
|
|
assertEquals(1, taskDao.deleteById(happyId));
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -149,7 +141,7 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
taskDao.save(task);
|
|
|
|
taskDao.save(task);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -157,14 +149,14 @@ public class TaskDaoTests extends InjectingTestCase {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testInvalidIndex() {
|
|
|
|
public void testInvalidIndex() {
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
|
|
|
|
|
|
|
|
assertNull(taskDao.fetch(1));
|
|
|
|
assertNull(taskDao.fetch(1));
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(0, taskDao.deleteById(1));
|
|
|
|
assertEquals(0, taskDao.deleteById(1));
|
|
|
|
|
|
|
|
|
|
|
|
// make sure db still works
|
|
|
|
// make sure db still works
|
|
|
|
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
|
|
|
|
assertEquals(0, taskDao.toList(Query.select()).size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|