fixed unit tests

pull/14/head
Tim Su 15 years ago
parent 36f9fda0cc
commit cca7b091b4

@ -1,15 +1,9 @@
package com.todoroo.astrid.gtasks; package com.todoroo.astrid.gtasks;
import android.content.BroadcastReceiver;
import android.content.Intent;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.GtasksIndentAction.GtasksDecreaseIndentAction;
import com.todoroo.astrid.gtasks.GtasksIndentAction.GtasksIncreaseIndentAction;
import com.todoroo.astrid.test.DatabaseTestCase; import com.todoroo.astrid.test.DatabaseTestCase;
import com.todoroo.gtasks.GoogleTaskListInfo; import com.todoroo.gtasks.GoogleTaskListInfo;
@ -17,13 +11,14 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
@Autowired private GtasksMetadataService gtasksMetadataService; @Autowired private GtasksMetadataService gtasksMetadataService;
@Autowired private GtasksListService gtasksListService; @Autowired private GtasksListService gtasksListService;
@Autowired private GtasksTaskListUpdater gtasksTaskListUpdater;
private Task task; private Task task;
public void testIndentWithoutMetadata() { public void testIndentWithoutMetadata() {
givenTask(taskWithoutMetadata()); givenTask(taskWithoutMetadata());
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
// should not crash // should not crash
} }
@ -31,7 +26,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
public void testIndentWithMetadataButNoOtherTasks() { public void testIndentWithMetadataButNoOtherTasks() {
givenTask(taskWithMetadata(0, 0)); givenTask(taskWithMetadata(0, 0));
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
thenExpectIndentationLevel(0); thenExpectIndentationLevel(0);
} }
@ -40,7 +35,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
taskWithMetadata(0, 0); taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0)); givenTask(taskWithMetadata(1, 0));
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
thenExpectIndentationLevel(1); thenExpectIndentationLevel(1);
} }
@ -48,7 +43,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
public void testDeindentWithMetadata() { public void testDeindentWithMetadata() {
givenTask(taskWithMetadata(0, 1)); givenTask(taskWithMetadata(0, 1));
whenTrigger(new GtasksDecreaseIndentAction()); whenDecreaseIndent();
thenExpectIndentationLevel(0); thenExpectIndentationLevel(0);
} }
@ -56,7 +51,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
public void testDeindentWithoutMetadata() { public void testDeindentWithoutMetadata() {
givenTask(taskWithoutMetadata()); givenTask(taskWithoutMetadata());
whenTrigger(new GtasksDecreaseIndentAction()); whenDecreaseIndent();
// should not crash // should not crash
} }
@ -64,7 +59,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
public void testDeindentWhenAlreadyZero() { public void testDeindentWhenAlreadyZero() {
givenTask(taskWithMetadata(0, 0)); givenTask(taskWithMetadata(0, 0));
whenTrigger(new GtasksDecreaseIndentAction()); whenDecreaseIndent();
thenExpectIndentationLevel(0); thenExpectIndentationLevel(0);
} }
@ -74,7 +69,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
givenTask(taskWithMetadata(1, 0)); givenTask(taskWithMetadata(1, 0));
Task child = taskWithMetadata(2, 1); Task child = taskWithMetadata(2, 1);
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
thenExpectIndentationLevel(1); thenExpectIndentationLevel(1);
thenExpectIndentationLevel(child, 2); thenExpectIndentationLevel(child, 2);
@ -85,7 +80,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
givenTask(taskWithMetadata(1, 1)); givenTask(taskWithMetadata(1, 1));
Task child = taskWithMetadata(2, 2); Task child = taskWithMetadata(2, 2);
whenTrigger(new GtasksDecreaseIndentAction()); whenDecreaseIndent();
thenExpectIndentationLevel(0); thenExpectIndentationLevel(0);
thenExpectIndentationLevel(child, 1); thenExpectIndentationLevel(child, 1);
@ -96,7 +91,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
givenTask(taskWithMetadata(1, 0)); givenTask(taskWithMetadata(1, 0));
Task sibling = taskWithMetadata(2, 0); Task sibling = taskWithMetadata(2, 0);
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
thenExpectIndentationLevel(1); thenExpectIndentationLevel(1);
thenExpectIndentationLevel(sibling, 0); thenExpectIndentationLevel(sibling, 0);
@ -108,7 +103,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
Task child = taskWithMetadata(2, 1); Task child = taskWithMetadata(2, 1);
Task grandchild = taskWithMetadata(3, 2); Task grandchild = taskWithMetadata(3, 2);
whenTrigger(new GtasksIncreaseIndentAction()); whenIncreaseIndent();
thenExpectIndentationLevel(1); thenExpectIndentationLevel(1);
thenExpectIndentationLevel(child, 2); thenExpectIndentationLevel(child, 2);
@ -117,6 +112,14 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
// --- helpers // --- helpers
private void whenIncreaseIndent() {
gtasksTaskListUpdater.indent(task.getId(), 1);
}
private void whenDecreaseIndent() {
gtasksTaskListUpdater.indent(task.getId(), -1);
}
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@ -151,12 +154,6 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
indentation == expected); indentation == expected);
} }
private void whenTrigger(BroadcastReceiver action) {
Intent intent = new Intent(AstridApiConstants.ACTION_TASK_CONTEXT_MENU);
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
action.onReceive(getContext(), intent);
}
private void givenTask(Task taskToTest) { private void givenTask(Task taskToTest) {
task = taskToTest; task = taskToTest;
} }

@ -214,7 +214,7 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
/** moveTo = null => move to end */ /** moveTo = null => move to end */
private void whenTriggerMove(Task target, Task moveTo) { private void whenTriggerMove(Task target, Task moveTo) {
gtasksTaskListUpdater.moveTo("1", target.getId(), moveTo == null ? -1 : moveTo.getId()); gtasksTaskListUpdater.moveTo(target.getId(), moveTo == null ? -1 : moveTo.getId());
gtasksTaskListUpdater.debugPrint("1"); gtasksTaskListUpdater.debugPrint("1");
} }

Loading…
Cancel
Save