Remove dead code, test methods from prod

pull/189/head
Alex Baker 11 years ago
parent 74f0ae9233
commit 570fe11d17

@ -177,15 +177,6 @@ abstract public class AbstractDatabase {
database = null;
}
/**
* Clear all data in database. Warning: this does what it says. Any open
* database resources will be abruptly closed.
*/
public synchronized final void clear() {
close();
ContextManager.getContext().deleteDatabase(getName());
}
/**
* @return sql database. opens database if not yet open
*/

@ -26,13 +26,6 @@ public abstract class Criterion {
}
};
public static Criterion none = new Criterion(Operator.exists) {
@Override
protected void populate(StringBuilder sb) {
sb.append(0);
}
};
public static Criterion and(final Criterion criterion, final Criterion... criterions) {
return new Criterion(Operator.and) {

@ -20,10 +20,6 @@ public class DateTimeUtils {
return new Date(year - 1900, month - 1, day);
}
public static Date newDate(int year, int month, int day, int hour, int minute, int second) {
return new Date(year - 1900, month - 1, day, hour, minute, second);
}
public static Date newDateUtc(int year, int month, int day, int hour, int minute, int second) {
return newDate(Date.UTC(year - 1900, month - 1, day, hour, minute, second));
}

@ -26,6 +26,7 @@ import static com.todoroo.andlib.utility.DateUtilities.getWeekdayShort;
import static com.todoroo.andlib.utility.DateUtilities.isEndOfMonth;
import static com.todoroo.andlib.utility.DateUtilities.oneMonthFromNow;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.newDate;
public class DateUtilitiesTest extends AndroidTestCase {
@ -96,23 +97,23 @@ public class DateUtilitiesTest extends AndroidTestCase {
public void testGet24HourTime() {
DateUtilities.is24HourOverride = true;
assertEquals("9:05", getTimeString(null, newDate(2014, 1, 4, 9, 5, 36)));
assertEquals("13:00", getTimeString(null, newDate(2014, 1, 4, 13, 0, 1)));
assertEquals("9:05", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("13:00", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 1)));
}
public void testGetTime() {
DateUtilities.is24HourOverride = false;
assertEquals("9:05 AM", getTimeString(null, newDate(2014, 1, 4, 9, 5, 36)));
assertEquals("1:05 PM", getTimeString(null, newDate(2014, 1, 4, 13, 5, 36)));
assertEquals("9:05 AM", getTimeString(null, newDateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("1:05 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 5, 36)));
}
public void testGetTimeWithNoMinutes() {
DateUtilities.is24HourOverride = false;
assertEquals("1 PM", getTimeString(null, newDate(2014, 1, 4, 13, 0, 59))); // derp?
assertEquals("1 PM", getTimeString(null, newDateTime(2014, 1, 4, 13, 0, 59))); // derp?
}
public void testGetDateStringWithYear() {
assertEquals("Jan 4, 2014", getDateString(newDate(2014, 1, 4, 0, 0, 0)));
assertEquals("Jan 4, 2014", getDateString(newDateTime(2014, 1, 4, 0, 0, 0)));
}
public void testGetDateStringHidingYear() {

@ -7,7 +7,6 @@ package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
@ -37,7 +36,7 @@ public class TaskDaoTests extends DatabaseTestCase {
// create task "happy"
Task task = new Task();
task.setTitle("happy");
assertTrue(taskDao.save(task));
taskDao.save(task);
cursor = taskDao.query(
Query.select(IDS));
assertEquals(1, cursor.getCount());
@ -50,7 +49,7 @@ public class TaskDaoTests extends DatabaseTestCase {
// create task "sad"
task = new Task();
task.setTitle("sad");
assertTrue(taskDao.save(task));
taskDao.save(task);
cursor = taskDao.query(
Query.select(IDS));
assertEquals(2, cursor.getCount());
@ -60,7 +59,7 @@ public class TaskDaoTests extends DatabaseTestCase {
long sadId = task.getId();
assertNotSame(Task.NO_ID, sadId);
task.setTitle("melancholy");
assertTrue(taskDao.save(task));
taskDao.save(task);
cursor = taskDao.query(
Query.select(IDS));
assertEquals(2, cursor.getCount());
@ -80,35 +79,35 @@ public class TaskDaoTests extends DatabaseTestCase {
// create normal task
Task task = new Task();
task.setTitle("normal");
assertTrue(taskDao.save(task));
taskDao.save(task);
// create blank task
task = new Task();
task.setTitle("");
assertTrue(taskDao.save(task));
taskDao.save(task);
// create hidden task
task = new Task();
task.setTitle("hidden");
task.setHideUntil(DateUtilities.now() + 10000);
assertTrue(taskDao.save(task));
taskDao.save(task);
// create task with deadlines
task = new Task();
task.setTitle("deadlineInFuture");
task.setDueDate(DateUtilities.now() + 10000);
assertTrue(taskDao.save(task));
taskDao.save(task);
task = new Task();
task.setTitle("deadlineInPast");
task.setDueDate(DateUtilities.now() - 10000);
assertTrue(taskDao.save(task));
taskDao.save(task);
// create completed task
task = new Task();
task.setTitle("completed");
task.setCompletionDate(DateUtilities.now() - 10000);
assertTrue(taskDao.save(task));
taskDao.save(task);
// check has no name
TodorooCursor<Task> cursor = taskDao.query(
@ -118,39 +117,12 @@ public class TaskDaoTests extends DatabaseTestCase {
assertEquals("", cursor.getString(1));
cursor.close();
// check has deadlines
cursor = taskDao.query(Query.select(TITLES).where(
TaskCriteria.hasDeadlines()).orderBy(Order.asc(Task.DUE_DATE)));
assertEquals(2, cursor.getCount());
cursor.moveToNext();
assertEquals("deadlineInPast", cursor.getString(1));
cursor.moveToNext();
assertEquals("deadlineInFuture", cursor.getString(1));
cursor.close();
// check is active
cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria.
isActive()));
assertEquals(5, cursor.getCount());
cursor.close();
// check due before / after
cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria.
dueBeforeNow()));
cursor.moveToNext();
assertEquals(1, cursor.getCount());
cursor.close();
cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria.
dueAfterNow()));
assertEquals(1, cursor.getCount());
cursor.close();
// check completed before
cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria.
completed()));
assertEquals(1, cursor.getCount());
cursor.close();
// check is visible
cursor = taskDao.query(Query.select(TITLES).where(TaskCriteria.
isVisible()));
@ -170,7 +142,7 @@ public class TaskDaoTests extends DatabaseTestCase {
// create task "happy"
Task task = new Task();
task.setTitle("happy");
assertTrue(taskDao.save(task));
taskDao.save(task);
cursor = taskDao.query(
Query.select(IDS));
assertEquals(1, cursor.getCount());
@ -196,7 +168,7 @@ public class TaskDaoTests extends DatabaseTestCase {
task.setTitle("happy");
task.setID(1L);
assertFalse(taskDao.save(task));
taskDao.save(task);
cursor = taskDao.query(
Query.select(IDS));

@ -22,6 +22,8 @@ import javax.inject.Inject;
@SuppressWarnings("nls")
public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
private static final int VALUE_UNSET = -1;
@Inject GtasksTaskListUpdater gtasksTaskListUpdater;
@Inject GtasksListService gtasksListService;
@Inject GtasksMetadataService gtasksMetadataService;
@ -80,7 +82,7 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
public void disabled_testNewTaskOrder() {
givenTasksABCDE();
Task newTask = createTask("F", GtasksMetadata.VALUE_UNSET, 0);
Task newTask = createTask("F", VALUE_UNSET, 0);
whenCalculatingOrder();
thenExpectMetadataIndentAndOrder(newTask, 5, 0);
@ -139,7 +141,13 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
}
private void whenCalculatingParentsAndSiblings() {
gtasksTaskListUpdater.createParentSiblingMaps();
createParentSiblingMaps();
}
void createParentSiblingMaps() {
for(StoreObject list : gtasksListService.getLists()) {
gtasksTaskListUpdater.updateParentSiblingMapsFor(list);
}
}
private void whenCalculatingOrder() {
@ -172,9 +180,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
taskService.save(task);
Metadata metadata = gtasksMetadata.createEmptyMetadata(task.getId());
metadata.setValue(GtasksMetadata.LIST_ID, "1");
if(order != GtasksMetadata.VALUE_UNSET)
if(order != VALUE_UNSET)
metadata.setValue(GtasksMetadata.ORDER, order);
if(indent != GtasksMetadata.VALUE_UNSET)
if(indent != VALUE_UNSET)
metadata.setValue(GtasksMetadata.INDENT, indent);
metadataService.save(metadata);
return task;

@ -22,6 +22,8 @@ import javax.inject.Inject;
@SuppressWarnings("nls")
public class GtasksTaskMovingTest extends DatabaseTestCase {
private static final int VALUE_UNSET = -1;
@Inject GtasksListService gtasksListService;
@Inject GtasksMetadataService gtasksMetadataService;
@Inject GtasksTaskListUpdater gtasksTaskListUpdater;
@ -281,9 +283,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
taskService.save(task);
Metadata metadata = gtasksMetadata.createEmptyMetadata(task.getId());
metadata.setValue(GtasksMetadata.LIST_ID, "1");
if(order != GtasksMetadata.VALUE_UNSET)
if(order != VALUE_UNSET)
metadata.setValue(GtasksMetadata.ORDER, order);
if(indent != GtasksMetadata.VALUE_UNSET)
if(indent != VALUE_UNSET)
metadata.setValue(GtasksMetadata.INDENT, indent);
metadataService.save(metadata);
return task;

@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.newDate;
public class AdvancedRepeatTest extends AndroidTestCase {
@ -46,7 +47,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
buildRRule(1, Frequency.DAILY);
// test specific day & time
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime());
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime());
task.setDueDate(dayWithTime);
long nextDayWithTime = dayWithTime + DateUtilities.ONE_DAY;
@ -58,7 +59,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
buildRRule(1, Frequency.DAILY);
// test specific day & time
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDate(2010, 8, 1, 10, 4, 0).getTime());
long dayWithTime = Task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, newDateTime(2010, 8, 1, 10, 4, 0).getTime());
task.setDueDate(dayWithTime);
Date todayWithTime = newDate();

@ -19,7 +19,8 @@ public abstract class DatabaseTestCase extends InjectingTestCase {
protected void setUp() {
super.setUp();
database.clear();
database.close();
getContext().deleteDatabase(database.getName());
database.openForWriting();
}

@ -93,11 +93,11 @@ public class AstridDefaultPreferenceSpecTest extends AndroidTestCase {
}
private boolean quietHoursEnabled() {
return preferences.getBoolean(R.string.p_rmd_enable_quiet);
return preferences.getBoolean(R.string.p_rmd_enable_quiet, false);
}
private boolean hasMigrated() {
return preferences.getBoolean(R.string.p_rmd_hasMigrated);
return preferences.getBoolean(R.string.p_rmd_hasMigrated, false);
}
private void setOldQuietHoursStart(int index) {

@ -2,6 +2,8 @@ package org.tasks;
import android.content.Context;
import java.util.Date;
public class TestUtilities {
private static boolean mockitoInitialized;
@ -12,4 +14,8 @@ public class TestUtilities {
mockitoInitialized = true;
}
}
public static Date newDateTime(int year, int month, int day, int hour, int minute, int second) {
return new Date(year - 1900, month - 1, day, hour, minute, second);
}
}

@ -9,6 +9,7 @@ import org.tasks.Snippet;
import java.util.Date;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.TestUtilities.newDateTime;
import static org.tasks.date.DateTimeUtils.currentTimeMillis;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateUtc;
@ -35,7 +36,7 @@ public class DateTimeUtilsTest extends AndroidTestCase {
}
public void testCreateNewDateTime() {
assertEquals(new Date(114, 0, 1, 15, 17, 53), newDate(2014, 1, 1, 15, 17, 53));
assertEquals(new Date(114, 0, 1, 15, 17, 53), newDateTime(2014, 1, 1, 15, 17, 53));
}
public void testCreateNewUtcDate() {

@ -15,7 +15,6 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
@ -109,7 +108,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
private static final long WAIT_BEFORE_AUTOSYNC = 2000L;
public static final int ACTIVITY_EDIT_TASK = 0;
public static final int ACTIVITY_SETTINGS = 1;
public static final int ACTIVITY_MENU_EXTERNAL = 4;
public static final int ACTIVITY_REQUEST_NEW_FILTER = 5;
// --- menu codes
@ -376,15 +374,6 @@ public class TaskListFragment extends InjectingListFragment implements OnSortSel
// Hook
}
protected void addMenuItem(Menu menu, CharSequence title, Drawable image, Intent customIntent, int id) {
Activity activity = getActivity();
if(!(activity instanceof TaskListActivity)) {
MenuItem item = menu.add(Menu.NONE, id, Menu.NONE, title);
item.setIcon(image);
item.setIntent(customIntent);
}
}
protected void setUpUiComponents() {
// set listener for quick-changing task priority
getListView().setOnKeyListener(new OnKeyListener() {

@ -102,26 +102,6 @@ public class TaskDao extends RemoteModelDao<Task> {
return Task.HIDE_UNTIL.lt(Functions.now());
}
/** @return tasks that have a due date */
public static Criterion hasDeadlines() {
return Task.DUE_DATE.neq(0);
}
/** @return tasks that are due before a certain unixtime */
public static Criterion dueBeforeNow() {
return Criterion.and(Task.DUE_DATE.gt(0), Task.DUE_DATE.lt(Functions.now()));
}
/** @return tasks that are due after a certain unixtime */
public static Criterion dueAfterNow() {
return Task.DUE_DATE.gt(Functions.now());
}
/** @return tasks completed before a given unixtime */
public static Criterion completed() {
return Criterion.and(Task.COMPLETION_DATE.gt(0), Task.COMPLETION_DATE.lt(Functions.now()));
}
/** @return tasks that have a blank or null title */
public static Criterion hasNoTitle() {
return Criterion.or(Task.TITLE.isNull(), Task.TITLE.eq(""));
@ -164,20 +144,17 @@ public class TaskDao extends RemoteModelDao<Task> {
*
* @return true if save occurred, false otherwise (i.e. nothing changed)
*/
public boolean save(Task task) {
boolean saveSuccessful;
public void save(Task task) {
if (task.getId() == Task.NO_ID) {
try {
saveSuccessful = createNew(task);
createNew(task);
} catch (SQLiteConstraintException e) {
log.error(e.getMessage(), e);
saveSuccessful = handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists
handleSQLiteConstraintException(task); // Tried to create task with remote id that already exists
}
} else {
saveSuccessful = saveExisting(task);
saveExisting(task);
}
return saveSuccessful;
}
public boolean handleSQLiteConstraintException(Task task) {

@ -23,8 +23,6 @@ import javax.inject.Singleton;
@Singleton
public class GtasksMetadata {
static final int VALUE_UNSET = -1;
/** metadata key */
public static final String METADATA_KEY = "gtasks"; //$NON-NLS-1$

@ -112,15 +112,6 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
// --- used during synchronization
/**
* Create a local tree of tasks to expedite sibling and parent lookups
*/
void createParentSiblingMaps() {
for(StoreObject list : gtasksListService.getLists()) {
updateParentSiblingMapsFor(list);
}
}
/**
* Update order, parent, and indentation fields for all tasks in the given list
*/
@ -190,7 +181,7 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
}
}
private void updateParentSiblingMapsFor(StoreObject list) {
void updateParentSiblingMapsFor(StoreObject list) {
final AtomicLong previousTask = new AtomicLong(Task.NO_ID);
final AtomicInteger previousIndent = new AtomicInteger(-1);
@ -233,6 +224,5 @@ public class GtasksTaskListUpdater extends OrderedMetadataListUpdater<StoreObjec
}
});
}
}

@ -117,10 +117,6 @@ public class Preferences {
}
}
public boolean getBoolean(int keyResources) {
return getBoolean(keyResources, false);
}
public boolean getBoolean(int keyResources, boolean defValue) {
return getBoolean(context.getString(keyResources), defValue);
}

Loading…
Cancel
Save