wrote a detail exposer test for gtasks

pull/14/head
Tim Su 14 years ago
parent 7e8c2321ce
commit 67451e623a

@ -1,7 +1,5 @@
package com.todoroo.astrid.gtasks;
import org.json.JSONException;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
@ -61,7 +59,7 @@ public class GtasksListService {
}
@SuppressWarnings("nls")
public void updateLists(GoogleTaskListInfo[] remoteLists) throws JSONException {
public void updateLists(GoogleTaskListInfo[] remoteLists) {
readLists();
for(int i = 0; i < remoteLists.length; i++) {
GoogleTaskListInfo remote = remoteLists[i];

@ -3,8 +3,6 @@
*/
package com.todoroo.astrid.gtasks;
import org.json.JSONException;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -35,16 +33,12 @@ public class GtasksSyncActionExposer extends BroadcastReceiver {
if(intent.getBooleanExtra("setup", false)) {
gtasksPreferenceService.setToken("haha");
try {
GoogleTaskListInfo[] newLists = new GoogleTaskListInfo[2];
GoogleTaskListInfo list = new GoogleTaskListInfo("1", "Tim's Tasks");
newLists[0] = list;
list = new GoogleTaskListInfo("2", "Travel");
newLists[1] = list;
gtasksListService.updateLists(newLists);
} catch (JSONException e) {
throw new RuntimeException(e);
}
GoogleTaskListInfo[] newLists = new GoogleTaskListInfo[2];
GoogleTaskListInfo list = new GoogleTaskListInfo("1", "Tim's Tasks");
newLists[0] = list;
list = new GoogleTaskListInfo("2", "Travel");
newLists[1] = list;
gtasksListService.updateLists(newLists);
System.err.println("you've ben set up the bomb.");
return;
}

@ -0,0 +1,122 @@
package com.todoroo.astrid.gtasks;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import com.todoroo.astrid.utility.Preferences;
import com.todoroo.gtasks.GoogleTaskListInfo;
public class GtasksDetailExposerTest extends DatabaseTestCase {
@Autowired private GtasksListService gtasksListService;
private GtasksTestPreferenceService preferences = new GtasksTestPreferenceService();
private Task task;
private String detail;
public void testExposeNotLoggedIn() {
givenTwoListSetup();
givenLoggedInStatus(false);
givenTaskWithList("listone-id");
whenRequestingDetails();
thenExpectNoDetail();
}
public void testExposeListOne() {
givenTwoListSetup();
givenLoggedInStatus(true);
givenTaskWithList("listone-id");
whenRequestingDetails();
thenExpectDetail("List One");
}
public void testExposeListTwo() {
givenTwoListSetup();
givenLoggedInStatus(true);
givenTaskWithList("listtwo-id");
whenRequestingDetails();
thenExpectDetail("List Two");
}
public void testExposeListDoesntExist() {
givenTwoListSetup();
givenLoggedInStatus(true);
givenTaskWithList("blah");
whenRequestingDetails();
thenExpectNoDetail();
}
public void testExposeListNotSet() {
givenTwoListSetup();
givenLoggedInStatus(true);
givenTaskWithList(null);
whenRequestingDetails();
thenExpectNoDetail();
}
// --- helpers
private void thenExpectNoDetail() {
assertNull("no detail", detail);
}
private void thenExpectDetail(String expected) {
assertNotNull("detail not null", detail);
assertTrue("detail was '" + detail + "', '" + expected + "' expected",
detail.contains(expected));
}
private void givenTwoListSetup() {
GoogleTaskListInfo[] newLists = new GoogleTaskListInfo[2];
GoogleTaskListInfo list = new GoogleTaskListInfo("listone-id", "List One");
newLists[0] = list;
list = new GoogleTaskListInfo("listtwo-id", "List Two");
newLists[1] = list;
gtasksListService.updateLists(newLists);
}
private Task givenTaskWithList(String list) {
Task newTask = new Task();
PluginServices.getTaskService().save(newTask);
Metadata metadata = GtasksMetadata.createEmptyMetadata(newTask.getId());
if(list != null)
metadata.setValue(GtasksMetadata.LIST_ID, list);
PluginServices.getMetadataService().save(metadata);
return task = newTask;
}
@Override
protected void addInjectables() {
super.addInjectables();
testInjector.addInjectable("gtasksPreferenceService", preferences);
}
private void whenRequestingDetails() {
detail = new GtasksDetailExposer().getTaskDetails(task.getId(), false);
}
private void givenLoggedInStatus(boolean status) {
preferences.setLoggedIn(status);
}
@Override
protected void setUp() throws Exception {
super.setUp();
if(!Preferences.isSet(GtasksPreferenceService.PREF_DEFAULT_LIST))
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, "list");
}
}
Loading…
Cancel
Save