Remove RemoteModelHelpers

pull/618/head
Alex Baker 6 years ago
parent 5e0d3dc129
commit 7510ee77a0

@ -1,9 +1,7 @@
package com.todoroo.astrid.model;
import android.content.ContentValues;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.data.Property;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
@ -14,14 +12,14 @@ import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
import java.util.Map;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.tasks.Freeze.freezeClock;
import static org.tasks.RemoteModelHelpers.asQueryProperties;
import static org.tasks.RemoteModelHelpers.compareRemoteModel;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
@RunWith(AndroidJUnit4.class)
@ -49,13 +47,14 @@ public class TaskTest extends InjectingTestCase {
Task task = new Task();
taskDao.save(task);
final Task fromDb = taskDao.fetch(task.getId());
assertEquals(task, fromDb);
compareRemoteModel(task, fromDb);
}
@Test
public void testDefaults() {
preferences.setDefaults();
ContentValues defaults = new Task().getDefaultValues();
Map<String, Object> defaults = new Task().getDefaultValues();
assertTrue(defaults.containsKey(Task.TITLE.name));
assertTrue(defaults.containsKey(Task.DUE_DATE.name));
assertTrue(defaults.containsKey(Task.HIDE_UNTIL.name));

@ -454,8 +454,6 @@ public class TitleParserTest extends InjectingTestCase {
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
task.clearValue(Task.ID);
task.clearValue(Task.UUID);
title = "Jog every day starting from today";
task = taskCreator.createWithValues(null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());
@ -480,8 +478,6 @@ public class TitleParserTest extends InjectingTestCase {
assertEquals(task.getRecurrence(), rrule.toIcal());
assertTrue(task.hasDueDate());
task.clearValue(Task.ID);
task.clearValue(Task.UUID);
title = "Jog every week starting from today";
task = taskCreator.createWithValues(null, title);
assertEquals(task.getRecurrence(), rrule.toIcal());

@ -1,53 +0,0 @@
package org.tasks;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Table;
import com.todoroo.astrid.data.Task;
import java.util.Set;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.fail;
@SuppressLint("NewApi")
public class RemoteModelHelpers {
public static Property[] asQueryProperties(Table table, ContentValues contentValues) {
Set<String> keys = contentValues.keySet();
Property[] result = new Property[keys.size()];
int index = 0;
for (String key : keys) {
result[index++] = new Property.StringProperty(table, key);
}
return result;
}
public static void compareRemoteModel(Task expected, Task actual) {
compareContentValues(expected.getSetValues(), actual.getSetValues());
compareContentValues(expected.getDatabaseValues(), actual.getDatabaseValues());
}
private static void compareContentValues(ContentValues expected, ContentValues actual) {
if (expected == null && actual == null) {
return;
}
if (expected == null || actual == null) {
fail();
}
for (String key : expected.keySet()) {
Object entry = expected.get(key);
if (entry instanceof Integer) {
assertEquals(entry, actual.getAsInteger(key));
} else if (entry instanceof String) {
assertEquals(entry, actual.getAsString(key));
} else if (entry instanceof Long) {
assertEquals(entry, actual.getAsLong(key));
} else {
fail("Unhandled property type: " + entry.getClass());
}
}
}
}

@ -81,11 +81,6 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
readPropertiesFromCursor(cursor);
}
/** Get database-read values for this object */
public ContentValues getDatabaseValues() {
return values;
}
/** Get the user-set values for this object */
public ContentValues getSetValues() {
return setValues;
@ -326,16 +321,6 @@ public abstract class AbstractModel implements Parcelable, Cloneable {
saver.save(property, setValues, value);
}
/**
* Merges content values with those coming from another source
*/
public synchronized void mergeWith(ContentValues other) {
if (setValues == null) {
setValues = new ContentValues();
}
setValues.putAll(other);
}
/**
* Merges set values with those coming from another source,
* keeping the existing value if one already exists

@ -217,8 +217,6 @@ public class TasksXmlImporter {
} else {
deserializeModel(currentTask, Task.PROPERTIES);
currentTask.setId(Task.NO_ID);
// Save the task to the database.
taskDao.save(currentTask);
importCount++;

Loading…
Cancel
Save