Fixed several subtasks unit tests to work with the new uuid scheme

pull/14/head
Sam Bosley 12 years ago
parent 428e021327
commit 5993424238

@ -2,6 +2,7 @@ package com.todoroo.astrid.subtasks;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
public class SubtasksHelperTest extends SubtasksTestCase {
@ -11,7 +12,9 @@ public class SubtasksHelperTest extends SubtasksTestCase {
protected void setUp() throws Exception {
super.setUp();
createTasks();
updater.initializeFromSerializedTree(SubtasksUpdater.ACTIVE_TASKS_ORDER, filter, DEFAULT_SERIALIZED_TREE);
TaskListMetadata m = new TaskListMetadata();
m.setValue(TaskListMetadata.FILTER, TaskListMetadata.FILTER_ID_ALL);
updater.initializeFromSerializedTree(m, filter, SubtasksHelper.convertTreeToRemoteIds(DEFAULT_SERIALIZED_TREE));
}
private Task createTask(String title, String uuid) {
@ -31,10 +34,10 @@ public class SubtasksHelperTest extends SubtasksTestCase {
F = createTask("F", "5"); // Local id 6
}
private static final Long[] EXPECTED_ORDER = {-1L, 1L, 2L, 3L, 4L, 5L, 6L };
private static final String[] EXPECTED_ORDER = { "-1", "1", "2", "3", "4", "5", "6" };
public void testOrderedIdArray() {
Long[] ids = SubtasksHelper.getIdArray(DEFAULT_SERIALIZED_TREE);
String[] ids = SubtasksHelper.getStringIdArray(DEFAULT_SERIALIZED_TREE);
assertEquals(EXPECTED_ORDER.length, ids.length);
for (int i = 0; i < EXPECTED_ORDER.length; i++) {
assertEquals(EXPECTED_ORDER[i], ids[i]);
@ -48,12 +51,4 @@ public class SubtasksHelperTest extends SubtasksTestCase {
String mapped = SubtasksHelper.convertTreeToRemoteIds(DEFAULT_SERIALIZED_TREE).replaceAll("\\s", "");
assertEquals(EXPECTED_REMOTE, mapped);
}
private static String EXPECTED_LOCAL = "[-1, [4, 5, [3, 2]], 6, 1]".replaceAll("\\s", "");
public void testRemoteToLocalIdMapping() {
String mapped = SubtasksHelper.convertTreeToLocalIds(DEFAULT_SERIALIZED_TREE).replaceAll("\\s", "");
assertEquals(EXPECTED_LOCAL, mapped);
}
}

@ -50,7 +50,7 @@ public class SubtasksMigrationTest extends SubtasksTestCase {
migrator.performMigration();
String newSerializedTree = getSerializedTree(tagData);
String expectedSerializedTree = DEFAULT_SERIALIZED_TREE;
String expectedSerializedTree = DEFAULT_SERIALIZED_TREE_STRING;
assertEquals(expectedSerializedTree, newSerializedTree);
}
@ -95,8 +95,8 @@ public class SubtasksMigrationTest extends SubtasksTestCase {
* A
*/
private static final String ACTIVE_TASKS_TREE = "[-1, [1, 2], [3, [4, 5], 6]]".replaceAll("\\s", "");
private static final String TAG_DATA_TREE = "[-1, 6, [5, 2, [4,3]], 1]".replaceAll("\\s", "");
private static final String ACTIVE_TASKS_TREE = "[\"-1\", [\"1\", \"2\"], [\"3\", [\"4\", \"5\"], \"6\"]]".replaceAll("\\s", "");
private static final String TAG_DATA_TREE = "[\"-1\", \"6\", [\"5\", \"2\", [\"4\",\"3\"]], \"1\"]".replaceAll("\\s", "");
private void createAdvancedMetadata(TagData tagData) {
createSubtasksMetadata(tagData, 6, 1, 0);

@ -2,6 +2,7 @@ package com.todoroo.astrid.subtasks;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
public class SubtasksMovingTest extends SubtasksTestCase {
@ -11,7 +12,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
protected void setUp() throws Exception {
super.setUp();
createTasks();
updater.initializeFromSerializedTree(SubtasksUpdater.ACTIVE_TASKS_ORDER, filter, DEFAULT_SERIALIZED_TREE);
TaskListMetadata m = new TaskListMetadata();
m.setValue(TaskListMetadata.FILTER, TaskListMetadata.FILTER_ID_ALL);
updater.initializeFromSerializedTree(m, filter, SubtasksHelper.convertTreeToRemoteIds(DEFAULT_SERIALIZED_TREE));
// Assert initial state is correct
expectParentAndPosition(A, null, 0);
@ -39,8 +42,8 @@ public class SubtasksMovingTest extends SubtasksTestCase {
}
private void whenTriggerMoveBefore(Task target, Task before) {
long beforeId = (before == null ? -1 : before.getId());
updater.moveTo(null, filter, target.getId(), beforeId);
String beforeId = (before == null ? "-1" : before.getUuid());
updater.moveTo(null, filter, target.getUuid(), beforeId);
}
/* Starting State (see SubtasksTestCase):

@ -4,6 +4,7 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.subtasks.AstridOrderedListUpdater.Node;
import com.todoroo.astrid.test.DatabaseTestCase;
@ -14,7 +15,7 @@ import com.todoroo.astrid.test.DatabaseTestCase;
*/
public class SubtasksTestCase extends DatabaseTestCase {
protected SubtasksUpdater<String> updater;
protected SubtasksUpdater<TaskListMetadata> updater;
protected Filter filter;
/* Starting State:
@ -27,6 +28,7 @@ public class SubtasksTestCase extends DatabaseTestCase {
* F
*/
public static final String DEFAULT_SERIALIZED_TREE = "[-1, [1, 2, [3, 4]], 5, 6]".replaceAll("\\s", "");
public static final String DEFAULT_SERIALIZED_TREE_STRING = "[\"-1\", [\"1\", \"2\", [\"3\", \"4\"]], \"5\", \"6\"]".replaceAll("\\s", "");
@Override
protected void setUp() throws Exception {
@ -37,10 +39,10 @@ public class SubtasksTestCase extends DatabaseTestCase {
}
protected void expectParentAndPosition(Task task, Task parent, int positionInParent) {
long parentId = (parent == null ? -1 : parent.getId());
Node n = updater.findNodeForTask(task.getId());
String parentId = (parent == null ? "-1" : parent.getUuid());
Node n = updater.findNodeForTask(task.getUuid());
assertNotNull("No node found for task " + task.getValue(Task.TITLE), n);
assertEquals("Parent mismatch", parentId, n.parent.taskId);
assertEquals("Parent mismatch", parentId, n.parent.uuid);
assertEquals("Position mismatch", positionInParent, n.parent.children.indexOf(n));
}

Loading…
Cancel
Save