cursor;
+ Filter filter = new Filter("bla", "bla", "WHERE 1", null);
+
+ Task task = new Task();
+ task.setValue(Task.TITLE, "evils");
+ assertTrue(taskService.save(task, false));
+
+ cursor = taskDao.fetch(database, Task.PROPERTIES, null, null);
+ assertEquals(1, cursor.getCount());
+ cursor.moveToNext();
+ task = new Task(cursor, Task.PROPERTIES);
+ assertEquals("evils", task.getValue(Task.TITLE));
+ cursor.close();
+
+ filter.sqlForNewTasks = String.format("UPDATE %s set %s = \"good\"",
+ Database.TASK_TABLE, Task.TITLE);
+ taskService.invokeSqlForNewTask(filter, task);
+
+ cursor = taskDao.fetch(database, Task.PROPERTIES, null, null);
+ assertEquals(1, cursor.getCount());
+ cursor.moveToNext();
+ task = new Task(cursor, Task.PROPERTIES);
+ assertEquals("good", task.getValue(Task.TITLE));
+ cursor.close();
+
+ filter.sqlForNewTasks = String.format("UPDATE %s set %s = \"yum\" WHERE %s = $ID",
+ Database.TASK_TABLE, Task.TITLE, Task.ID);
+ taskService.invokeSqlForNewTask(filter, task);
+
+ cursor = taskDao.fetch(database, Task.PROPERTIES, null, null);
+ assertEquals(1, cursor.getCount());
+ cursor.moveToNext();
+ task = new Task(cursor, Task.PROPERTIES);
+ assertEquals("yum", task.getValue(Task.TITLE));
+ cursor.close();
+ }
+
+
+}
diff --git a/tests/src/com/todoroo/astrid/test/AstridActivityTestCase.java b/tests/src/com/todoroo/astrid/test/AstridActivityTestCase.java
new file mode 100644
index 000000000..b44a96a34
--- /dev/null
+++ b/tests/src/com/todoroo/astrid/test/AstridActivityTestCase.java
@@ -0,0 +1,96 @@
+package com.todoroo.astrid.test;
+
+import android.app.Activity;
+import android.content.pm.ActivityInfo;
+import android.test.ActivityInstrumentationTestCase2;
+import android.view.MotionEvent;
+
+import com.todoroo.andlib.service.Autowired;
+import com.todoroo.andlib.service.DependencyInjectionService;
+import com.todoroo.andlib.service.TestDependencyInjector;
+import com.todoroo.astrid.dao.Database;
+import com.todoroo.astrid.service.AstridDependencyInjector;
+import com.todoroo.astrid.test.DatabaseTestCase.AstridTestDatabase;
+
+/**
+ * ActivityTestCase is a helper for testing Todoroo Activities.
+ *
+ * It initializes a test database before the activity is created.
+ *
+ * @author Tim Su
+ *
+ * @param
+ */
+public class AstridActivityTestCase extends ActivityInstrumentationTestCase2 {
+
+ @Autowired
+ public Database database;
+
+ static {
+ AstridDependencyInjector.initialize();
+ TestDependencyInjector.initialize("db").addInjectable("database",
+ new AstridTestDatabase());
+ }
+
+ public AstridActivityTestCase(String packageName, Class activityClass) {
+ super(packageName, activityClass);
+ DependencyInjectionService.getInstance().inject(this);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // create new test database
+ AstridTestDatabase.dropTables(getInstrumentation().getTargetContext());
+ database.openForWriting();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if(database != null)
+ database.close();
+ }
+
+ /**
+ * Call to just tear this activity down
+ */
+ protected void tearActivityDown() throws Exception {
+ super.tearDown();
+ }
+
+ /**
+ * Call to just set this activity up
+ */
+ protected void setActivityUp() throws Exception {
+ super.setUp();
+ }
+
+ /** Calls various lifecycle methods, makes sure all of them work */
+ public void testLifecycle() throws Exception {
+ T activity = getActivity();
+ getInstrumentation().callActivityOnPause(activity);
+ Thread.sleep(500);
+ getInstrumentation().callActivityOnResume(activity);
+
+ getInstrumentation().sendPointerSync(MotionEvent.obtain(500, 500, MotionEvent.ACTION_DOWN, 10, 30, 0));
+
+ getInstrumentation().callActivityOnPause(activity);
+ getInstrumentation().callActivityOnStop(activity);
+ Thread.sleep(500);
+ getInstrumentation().callActivityOnRestart(activity);
+ getInstrumentation().callActivityOnStart(activity);
+ getInstrumentation().callActivityOnResume(activity);
+
+ getInstrumentation().sendPointerSync(MotionEvent.obtain(500, 500, MotionEvent.ACTION_DOWN, 10, 30, 0));
+
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ Thread.sleep(500);
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ Thread.sleep(1000);
+ }
+
+
+}
diff --git a/tests/src/com/todoroo/astrid/test/DatabaseTestCase.java b/tests/src/com/todoroo/astrid/test/DatabaseTestCase.java
new file mode 100644
index 000000000..6423d53ae
--- /dev/null
+++ b/tests/src/com/todoroo/astrid/test/DatabaseTestCase.java
@@ -0,0 +1,70 @@
+package com.todoroo.astrid.test;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteOpenHelper;
+
+import com.todoroo.andlib.service.Autowired;
+import com.todoroo.andlib.service.TestDependencyInjector;
+import com.todoroo.andlib.test.TodorooTestCase;
+import com.todoroo.astrid.dao.Database;
+import com.todoroo.astrid.dao.Database.AstridSQLiteOpenHelper;
+import com.todoroo.astrid.service.AstridDependencyInjector;
+
+/**
+ * Test case that automatically sets up and tears down a test database
+ *
+ * @author Tim Su
+ *
+ */
+public class DatabaseTestCase extends TodorooTestCase {
+
+ @Autowired
+ public Database database;
+
+ static {
+ AstridDependencyInjector.initialize();
+ TestDependencyInjector.initialize("db").addInjectable("database",
+ new AstridTestDatabase());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ // create new test database
+ AstridTestDatabase.dropTables(getContext());
+ database.openForWriting();
+
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ database.close();
+ }
+
+ public static class AstridTestDatabase extends Database {
+
+ private static final String NAME = "todoroo-test";
+
+ @Override
+ public synchronized void openForWriting() {
+ if(helper == null)
+ helper = new AstridSQLiteOpenHelper(context, NAME, null, VERSION);
+ super.openForWriting();
+ }
+
+ @Override
+ public synchronized void openForReading() {
+ if(helper == null)
+ helper = new AstridSQLiteOpenHelper(context, NAME, null, VERSION);
+ super.openForWriting();
+ }
+
+ public static void dropTables(Context context) {
+ // force drop database
+ SQLiteOpenHelper helper = new AstridSQLiteOpenHelper(context, NAME, null, VERSION);
+ helper.onUpgrade(helper.getWritableDatabase(),
+ 0, VERSION);
+ helper.close();
+ }
+ }
+}
diff --git a/tests/src/com/todoroo/astrid/upgrade/Astrid2To3UpgradeTests.java b/tests/src/com/todoroo/astrid/upgrade/Astrid2To3UpgradeTests.java
new file mode 100644
index 000000000..96b186486
--- /dev/null
+++ b/tests/src/com/todoroo/astrid/upgrade/Astrid2To3UpgradeTests.java
@@ -0,0 +1,7 @@
+package com.todoroo.astrid.upgrade;
+
+import com.todoroo.astrid.test.DatabaseTestCase;
+
+public class Astrid2To3UpgradeTests extends DatabaseTestCase {
+
+}