diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index e66edd796..bd06980da 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -17,22 +17,22 @@ import com.todoroo.astrid.data.OutstandingEntry; import com.todoroo.astrid.data.RemoteModel; @SuppressWarnings("nls") -public class ChangesHappened implements ClientToServerMessage { +public class ChangesHappened> implements ClientToServerMessage { private final Class modelClass; - private final Class> outstandingClass; + private final Class outstandingClass; private final long id; private final long uuid; - private final List> changes; + private final List changes; private long pushedAt; - private final OutstandingEntryDao> outstandingDao; + private final OutstandingEntryDao outstandingDao; public ChangesHappened(TYPE entity, RemoteModelDao modelDao, - OutstandingEntryDao> outstandingDao) { + OutstandingEntryDao outstandingDao) { this.modelClass = entity.getClass(); this.outstandingClass = getOutstandingClass(modelClass); this.id = entity.getId(); - this.changes = new ArrayList>(); + this.changes = new ArrayList(); this.outstandingDao = outstandingDao; if (!entity.containsValue(RemoteModel.REMOTE_ID_PROPERTY) @@ -53,13 +53,17 @@ public class ChangesHappened implements ClientToServer // Process changes list and send to server } + public List getChanges() { + return changes; + } + private void populateChanges() { - TodorooCursor> cursor = outstandingDao.query(Query.select(getModelProperties(outstandingClass)) + TodorooCursor cursor = outstandingDao.query(Query.select(getModelProperties(outstandingClass)) .where(OutstandingEntry.ENTITY_ID_PROPERTY.eq(id)).orderBy(Order.asc(OutstandingEntry.CREATED_AT_PROPERTY))); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { try { - OutstandingEntry instance = outstandingClass.newInstance(); + OE instance = outstandingClass.newInstance(); instance.readPropertiesFromCursor(cursor); changes.add(instance); } catch (IllegalAccessException e) { @@ -73,9 +77,9 @@ public class ChangesHappened implements ClientToServer } } - private Class> getOutstandingClass(Class model) { + private Class getOutstandingClass(Class model) { try { - return (Class>) getStaticFieldByReflection(model, "OUTSTANDING_MODEL"); + return (Class) getStaticFieldByReflection(model, "OUTSTANDING_MODEL"); } catch (ClassCastException e) { throw new RuntimeException("OUTSTANDING_MODEL field for class " + model.getName() + " is not of the correct type"); } diff --git a/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java b/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java new file mode 100644 index 000000000..72c9d9120 --- /dev/null +++ b/tests-sync/src/com/todoroo/astrid/sync/NewSyncTestCase.java @@ -0,0 +1,39 @@ +package com.todoroo.astrid.sync; + +import com.todoroo.andlib.service.Autowired; +import com.todoroo.astrid.dao.TagDataDao; +import com.todoroo.astrid.dao.TagOutstandingDao; +import com.todoroo.astrid.dao.TaskDao; +import com.todoroo.astrid.dao.TaskOutstandingDao; +import com.todoroo.astrid.data.TagData; +import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.test.DatabaseTestCase; + +public class NewSyncTestCase extends DatabaseTestCase { + @Autowired + protected TaskDao taskDao; + @Autowired + protected TagDataDao tagDataDao; + + @Autowired + protected TaskOutstandingDao taskOutstandingDao; + @Autowired + protected + TagOutstandingDao tagOutstandingDao; + + protected Task createTask() { + Task task = new Task(); + task.setValue(Task.TITLE, "new task"); + + taskDao.createNew(task); + return task; + } + + protected TagData createTagData() { + TagData tag = new TagData(); + tag.setValue(TagData.NAME, "new tag"); + + tagDataDao.createNew(tag); + return tag; + } +} diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java new file mode 100644 index 000000000..7fbd89450 --- /dev/null +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncMessageTest.java @@ -0,0 +1,19 @@ +package com.todoroo.astrid.sync; + +import com.todoroo.astrid.actfm.sync.messages.ChangesHappened; +import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskOutstanding; + +public class SyncMessageTest extends NewSyncTestCase { + + public void testTaskChangesHappenedConstructor() { + Task t = createTask(); + try { + ChangesHappened changes = new ChangesHappened(t, taskDao, taskOutstandingDao); + assertTrue(changes.getChanges().size() > 0); + } catch (Exception e) { + fail("ChangesHappened constructor threw exception " + e); + } + } + +} diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java index 8a171e5a5..973675491 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java @@ -17,13 +17,7 @@ import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskOutstanding; import com.todoroo.astrid.test.DatabaseTestCase; -public class SyncModelTest extends DatabaseTestCase { - - @Autowired TaskDao taskDao; - @Autowired TagDataDao tagDataDao; - - @Autowired TaskOutstandingDao taskOutstandingDao; - @Autowired TagOutstandingDao tagOutstandingDao; +public class SyncModelTest extends NewSyncTestCase { public void testCreateTaskMakesUuid() { Task task = createTask(); @@ -96,21 +90,4 @@ public class SyncModelTest extends DatabaseTestCase { cursor.close(); } } - - private Task createTask() { - Task task = new Task(); - task.setValue(Task.TITLE, "new task"); - - taskDao.createNew(task); - return task; - } - - private TagData createTagData() { - TagData tag = new TagData(); - tag.setValue(TagData.NAME, "new tag"); - - tagDataDao.createNew(tag); - return tag; - } - }