pull/467/head
Alex Baker 8 years ago
parent 2d53546797
commit 1e4f0ca527

@ -3,7 +3,7 @@ sudo: false
jdk: oraclejdk8
env:
matrix:
- ANDROID_SDKS=android-23,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
- ANDROID_TARGET=android-21 ANDROID_ABI=armeabi-v7a
android:
components:
- tools # https://github.com/travis-ci/travis-ci/issues/5049

@ -36,7 +36,7 @@ android {
minSdkVersion 15
targetSdkVersion 24
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
@ -106,6 +106,7 @@ final BUTTERKNIFE_VERSION = '8.3.0'
final GPS_VERSION = '9.4.0'
final SUPPORT_VERSION = '24.2.0'
final STETHO_VERSION = '1.3.1'
final TESTING_SUPPORT_VERSION = '0.5'
dependencies {
annotationProcessor "com.google.dagger:dagger-compiler:${DAGGER_VERSION}"
@ -151,4 +152,7 @@ dependencies {
androidTestAnnotationProcessor "com.jakewharton:butterknife-compiler:${BUTTERKNIFE_VERSION}"
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.natpryce:make-it-easy:4.0.0'
androidTestCompile "com.android.support.test:runner:${TESTING_SUPPORT_VERSION}"
androidTestCompile "com.android.support.test:rules:${TESTING_SUPPORT_VERSION}"
androidTestCompile "com.android.support:support-annotations:${SUPPORT_VERSION}"
}

@ -8,9 +8,9 @@ package com.todoroo.andlib.test;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.util.DisplayMetrics;
import org.junit.Test;
import org.tasks.R;
import org.tasks.time.DateTime;
@ -19,6 +19,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.tasks.date.DateTimeUtils.newDateTime;
/**
@ -29,7 +33,7 @@ import static org.tasks.date.DateTimeUtils.newDateTime;
* @author Tim Su <tim@todoroo.com>
*
*/
abstract public class TranslationTests extends AndroidTestCase {
abstract public class TranslationTests {
// --- abstract methods
@ -57,8 +61,8 @@ abstract public class TranslationTests extends AndroidTestCase {
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
getContext().getResources().updateConfiguration(config, metrics);
DisplayMetrics metrics = getTargetContext().getResources().getDisplayMetrics();
getTargetContext().getResources().updateConfiguration(config, metrics);
}
/**
@ -135,6 +139,7 @@ abstract public class TranslationTests extends AndroidTestCase {
/**
* Internal test of format string parser
*/
@Test
public void testFormatStringParser() {
String s = "abc";
FormatStringData data = new FormatStringData(s);
@ -168,8 +173,9 @@ abstract public class TranslationTests extends AndroidTestCase {
* Test that the format specifiers in translations match exactly the
* translations in the default text
*/
@Test
public void testFormatStringsMatch() throws Exception {
final Resources r = getContext().getResources();
final Resources r = getTargetContext().getResources();
final int[] strings = getResourceIds(getStringResources());
final FormatStringData[] formatStrings = new FormatStringData[strings.length];
@ -216,8 +222,9 @@ abstract public class TranslationTests extends AndroidTestCase {
/**
* Test that date formatters parse correctly
*/
@Test
public void testDateFormats() throws Exception {
final Resources r = getContext().getResources();
final Resources r = getTargetContext().getResources();
final StringBuilder failures = new StringBuilder();
final int[] dateStrings = getDateFormatStrings();
@ -250,8 +257,9 @@ abstract public class TranslationTests extends AndroidTestCase {
/**
* Test that there are the same number of array entries in each locale
*/
@Test
public void testArraySizesMatch() throws Exception {
final Resources r = getContext().getResources();
final Resources r = getTargetContext().getResources();
final int[] arrays = getResourceIds(getArrayResources());
final int[] sizes = new int[arrays.length];
final StringBuilder failures = new StringBuilder();

@ -6,14 +6,19 @@
package com.todoroo.andlib.utility;
import android.content.res.Configuration;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import android.util.DisplayMetrics;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Snippet;
import org.tasks.time.DateTime;
import java.util.Locale;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static com.todoroo.andlib.utility.DateUtilities.addCalendarMonthsToUnixtime;
import static com.todoroo.andlib.utility.DateUtilities.getDateString;
import static com.todoroo.andlib.utility.DateUtilities.getStartOfDay;
@ -21,21 +26,23 @@ import static com.todoroo.andlib.utility.DateUtilities.getTimeString;
import static com.todoroo.andlib.utility.DateUtilities.getWeekday;
import static com.todoroo.andlib.utility.DateUtilities.getWeekdayShort;
import static com.todoroo.andlib.utility.DateUtilities.oneMonthFromNow;
import static junit.framework.Assert.assertEquals;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateTime;
public class DateUtilitiesTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class DateUtilitiesTest {
private static Locale defaultLocale;
@Override
@Before
public void setUp() {
defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
}
@Override
@After
public void tearDown() {
DateUtilities.is24HourOverride = null;
Locale.setDefault(defaultLocale);
@ -45,8 +52,8 @@ public class DateUtilitiesTest extends AndroidTestCase {
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
getContext().getResources().updateConfiguration(config, metrics);
DisplayMetrics metrics = getTargetContext().getResources().getDisplayMetrics();
getTargetContext().getResources().updateConfiguration(config, metrics);
}
public void forEachLocale(Runnable r) {
@ -58,6 +65,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}
}
@Test
public void testTimeString() {
forEachLocale(() -> {
DateTime d = newDateTime();
@ -65,17 +73,18 @@ public class DateUtilitiesTest extends AndroidTestCase {
DateUtilities.is24HourOverride = false;
for (int i = 0; i < 24; i++) {
d = d.withHourOfDay(i);
getTimeString(getContext(), d);
getTimeString(getTargetContext(), d);
}
DateUtilities.is24HourOverride = true;
for (int i = 0; i < 24; i++) {
d = d.withHourOfDay(i);
getTimeString(getContext(), d);
getTimeString(getTargetContext(), d);
}
});
}
@Test
public void testDateString() {
forEachLocale(() -> {
DateTime d = newDateTime();
@ -87,39 +96,46 @@ public class DateUtilitiesTest extends AndroidTestCase {
});
}
@Test
public void testGet24HourTime() {
DateUtilities.is24HourOverride = true;
assertEquals("09:05", getTimeString(null, new DateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("13:00", getTimeString(null, new DateTime(2014, 1, 4, 13, 0, 1)));
}
@Test
public void testGetTime() {
DateUtilities.is24HourOverride = false;
assertEquals("9:05 AM", getTimeString(null, new DateTime(2014, 1, 4, 9, 5, 36)));
assertEquals("1:05 PM", getTimeString(null, new DateTime(2014, 1, 4, 13, 5, 36)));
}
@Test
public void testGetTimeWithNoMinutes() {
DateUtilities.is24HourOverride = false;
assertEquals("1 PM", getTimeString(null, new DateTime(2014, 1, 4, 13, 0, 59))); // derp?
}
@Test
public void testGetDateStringWithYear() {
assertEquals("Jan 4 '14", getDateString(new DateTime(2014, 1, 4, 0, 0, 0)));
}
@Test
public void testGetDateStringHidingYear() {
freezeAt(newDate(2014, 1, 1)).thawAfter(new Snippet() {{
assertEquals("Jan 1", getDateString(newDateTime()));
}});
}
@Test
public void testGetDateStringWithDifferentYear() {
freezeAt(newDate(2013, 12, 31)).thawAfter(new Snippet() {{
assertEquals("Jan 1 '14", getDateString(new DateTime(2014, 1, 1, 0, 0, 0)));
}});
}
@Test
public void testOneMonthFromStartOfDecember() {
DateTime now = new DateTime(2013, 12, 1, 12, 19, 45, 192);
final long expected = new DateTime(2014, 1, 1, 12, 19, 45, 192).getMillis();
@ -129,6 +145,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
@Test
public void testOneMonthFromEndOfDecember() {
DateTime now = new DateTime(2013, 12, 31, 16, 31, 20, 597);
final long expected = new DateTime(2014, 1, 31, 16, 31, 20, 597).getMillis();
@ -138,6 +155,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
@Test
public void testGetSixMonthsFromEndOfDecember() {
final DateTime now = new DateTime(2013, 12, 31, 17, 17, 32, 900);
final long expected = new DateTime(2014, 7, 1, 17, 17, 32, 900).getMillis();
@ -147,6 +165,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
@Test
public void testOneMonthFromEndOfJanuary() {
DateTime now = new DateTime(2014, 1, 31, 12, 54, 33, 175);
final long expected = new DateTime(2014, 3, 3, 12, 54, 33, 175).getMillis();
@ -156,6 +175,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
@Test
public void testOneMonthFromEndOfFebruary() {
DateTime now = new DateTime(2014, 2, 28, 9, 19, 7, 990);
final long expected = new DateTime(2014, 3, 28, 9, 19, 7, 990).getMillis();
@ -165,6 +185,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
}});
}
@Test
public void testShouldGetStartOfDay() {
DateTime now = new DateTime(2014, 1, 3, 10, 41, 41, 520);
assertEquals(
@ -172,6 +193,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
getStartOfDay(now.getMillis()));
}
@Test
public void testGetWeekdayLongString() {
assertEquals("Sunday", getWeekday(newDate(2013, 12, 29)));
assertEquals("Monday", getWeekday(newDate(2013, 12, 30)));
@ -182,6 +204,7 @@ public class DateUtilitiesTest extends AndroidTestCase {
assertEquals("Saturday", getWeekday(newDate(2014, 1, 4)));
}
@Test
public void testGetWeekdayShortString() {
assertEquals("Sun", getWeekdayShort(newDate(2013, 12, 29)));
assertEquals("Mon", getWeekdayShort(newDate(2013, 12, 30)));
@ -192,15 +215,18 @@ public class DateUtilitiesTest extends AndroidTestCase {
assertEquals("Sat", getWeekdayShort(newDate(2014, 1, 4)));
}
@Test
public void testAddMonthsToTimestamp() {
assertEquals(newDate(2014, 1, 1).getMillis(), addCalendarMonthsToUnixtime(newDate(2013, 12, 1).getMillis(), 1));
assertEquals(newDate(2014, 12, 31).getMillis(), addCalendarMonthsToUnixtime(newDate(2013, 12, 31).getMillis(), 12));
}
@Test
public void testAddMonthsWithLessDays() {
assertEquals(newDate(2014, 3, 3).getMillis(), addCalendarMonthsToUnixtime(newDate(2013, 12, 31).getMillis(), 2));
}
@Test
public void testAddMonthsWithMoreDays() {
assertEquals(newDate(2014, 1, 30).getMillis(), addCalendarMonthsToUnixtime(newDate(2013, 11, 30).getMillis(), 2));
}

@ -1,65 +1,79 @@
package com.todoroo.andlib.utility;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.time.DateTime;
import java.util.Locale;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static com.todoroo.andlib.utility.DateUtilities.getRelativeDay;
import static junit.framework.Assert.assertEquals;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.Freeze.thaw;
public class RelativeDayTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class RelativeDayTest {
private static Locale defaultLocale;
private static final DateTime now = new DateTime(2013, 12, 31, 11, 9, 42, 357);
@Override
@Before
public void setUp() {
defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
freezeAt(now);
}
@Override
@After
public void tearDown() {
Locale.setDefault(defaultLocale);
thaw();
}
@Test
public void testRelativeDayIsToday() {
checkRelativeDay(new DateTime(), "Today", "Today");
}
@Test
public void testRelativeDayIsTomorrow() {
checkRelativeDay(new DateTime().plusDays(1), "Tomorrow", "Tmrw");
}
@Test
public void testRelativeDayIsYesterday() {
checkRelativeDay(new DateTime().minusDays(1), "Yesterday", "Yest");
}
@Test
public void testRelativeDayTwo() {
checkRelativeDay(new DateTime().minusDays(2), "Sunday", "Sun");
checkRelativeDay(new DateTime().plusDays(2), "Thursday", "Thu");
}
@Test
public void testRelativeDaySix() {
checkRelativeDay(new DateTime().minusDays(6), "Wednesday", "Wed");
checkRelativeDay(new DateTime().plusDays(6), "Monday", "Mon");
}
@Test
public void testRelativeDayOneWeek() {
checkRelativeDay(new DateTime().minusDays(7), "Dec 24", "Dec 24");
}
@Test
public void testRelativeDayOneWeekNextYear() {
checkRelativeDay(new DateTime().plusDays(7), "Jan 7 '14", "Jan 7 '14");
}
private void checkRelativeDay(DateTime now, String full, String abbreviated) {
assertEquals(full, getRelativeDay(getContext(), now.getMillis(), false));
assertEquals(abbreviated, getRelativeDay(getContext(), now.getMillis(), true));
assertEquals(full, getRelativeDay(getTargetContext(), now.getMillis(), false));
assertEquals(abbreviated, getRelativeDay(getTargetContext(), now.getMillis(), true));
}
}

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.dao;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
@ -12,12 +14,23 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
@RunWith(AndroidJUnit4.class)
public class MetadataDaoTests extends DatabaseTestCase {
@Inject MetadataDao metadataDao;
@ -41,6 +54,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
/**
* Test basic creation, fetch, and save
*/
@Test
public void testCrud() throws Exception {
assertTrue(metadataDao.toList(Query.select(Metadata.ID)).isEmpty());
@ -85,7 +99,9 @@ public class MetadataDaoTests extends DatabaseTestCase {
/**
* Test metadata bound to task
*/
public void disabled_testMetadataConditions() {
@Ignore
@Test
public void testMetadataConditions() {
// create "happy"
Metadata metadata = new Metadata();
metadata.setKey("with1");
@ -113,6 +129,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
assertEquals(1, metadataDao.toList(Query.select(KEYS)).size());
}
@Test
public void testDontSaveMetadataWithoutTaskId() {
try {
metadataDao.persist(metadata);
@ -122,6 +139,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
}
}
@Test
public void testSaveMetadata() {
metadata.setTask(1L);
metadataDao.persist(metadata);
@ -129,6 +147,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
assertNotNull(metadataDao.fetch(metadata.getId()));
}
@Test
public void testDontDeleteValidMetadata() {
final Task task = new Task();
taskDao.save(task);
@ -140,6 +159,7 @@ public class MetadataDaoTests extends DatabaseTestCase {
assertNotNull(metadataDao.fetch(metadata.getId()));
}
@Test
public void testDeleteDangling() {
metadata.setTask(1L);
metadataDao.persist(metadata);

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.dao;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
@ -12,12 +14,22 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class TaskDaoTests extends DatabaseTestCase {
public static Property<?>[] IDS = new Property<?>[] { Task.ID };
@ -30,7 +42,9 @@ public class TaskDaoTests extends DatabaseTestCase {
/**
* Test basic task creation, fetch, and save
*/
public void disabled_testTaskCreation() {
@Ignore
@Test
public void testTaskCreation() {
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
// create task "happy"
@ -66,7 +80,9 @@ public class TaskDaoTests extends DatabaseTestCase {
/**
* Test various task fetch conditions
*/
public void disabled_testTaskConditions() {
@Ignore
@Test
public void testTaskConditions() {
// create normal task
Task task = new Task();
task.setTitle("normal");
@ -115,7 +131,9 @@ public class TaskDaoTests extends DatabaseTestCase {
/**
* Test task deletion
*/
public void disabled_testTDeletion() {
@Ignore
@Test
public void testTDeletion() {
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
// create task "happy"
@ -133,7 +151,9 @@ public class TaskDaoTests extends DatabaseTestCase {
/**
* Test save without prior create doesn't work
*/
public void disabled_testSaveWithoutCreate() {
@Ignore
@Test
public void testSaveWithoutCreate() {
// try to save task "happy"
Task task = new Task();
task.setTitle("happy");
@ -147,7 +167,9 @@ public class TaskDaoTests extends DatabaseTestCase {
/**
* Test passing invalid task indices to various things
*/
public void disabled_testInvalidIndex() {
@Ignore
@Test
public void testInvalidIndex() {
assertEquals(0, taskDao.toList(Query.select(IDS)).size());
assertNull(taskDao.fetch(1, IDS));

@ -1,9 +1,13 @@
package com.todoroo.astrid.data;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.tasks.time.DateTime;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Snippet;
import org.tasks.time.DateTime;
import java.util.ArrayList;
import java.util.TreeSet;
@ -23,60 +27,72 @@ import static com.todoroo.astrid.data.Task.URGENCY_TODAY;
import static com.todoroo.astrid.data.Task.URGENCY_TOMORROW;
import static com.todoroo.astrid.data.Task.createDueDate;
import static com.todoroo.astrid.data.Task.hasDueTime;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.Freeze.thaw;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
public class TaskTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class TaskTest {
private static final DateTime now = new DateTime(2013, 12, 31, 16, 10, 53, 452);
private static final DateTime specificDueDate = new DateTime(2014, 3, 17, 9, 54, 27, 959);
@Override
@Before
public void setUp() {
freezeAt(now);
}
@Override
@After
public void tearDown() {
thaw();
}
@Test
public void testCreateDueDateNoUrgency() {
assertEquals(0, createDueDate(URGENCY_NONE, 1L));
}
@Test
public void testCreateDueDateToday() {
long expected = new DateTime(2013, 12, 31, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_TODAY, -1L));
}
@Test
public void testCreateDueDateTomorrow() {
long expected = new DateTime(2014, 1, 1, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_TOMORROW, -1L));
}
@Test
public void testCreateDueDateDayAfter() {
long expected = new DateTime(2014, 1, 2, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_DAY_AFTER, -1L));
}
@Test
public void testCreateDueDateNextWeek() {
long expected = new DateTime(2014, 1, 7, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_NEXT_WEEK, -1L));
}
@Test
public void testCreateDueDateInTwoWeeks() {
long expected = new DateTime(2014, 1, 14, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_IN_TWO_WEEKS, -1L));
}
@Test
public void testCreateDueDateNextMonth() {
long expected = new DateTime(2014, 1, 31, 12, 0, 0, 0).getMillis();
assertEquals(expected, createDueDate(URGENCY_NEXT_MONTH, -1L));
}
@Test
public void testRemoveTimeForSpecificDay() {
long expected = specificDueDate
.withHourOfDay(12)
@ -87,6 +103,7 @@ public class TaskTest extends AndroidTestCase {
assertEquals(expected, createDueDate(URGENCY_SPECIFIC_DAY, specificDueDate.getMillis()));
}
@Test
public void testRemoveSecondsForSpecificTime() {
long expected = specificDueDate
.withSecondOfMinute(1)
@ -95,6 +112,7 @@ public class TaskTest extends AndroidTestCase {
assertEquals(expected, createDueDate(URGENCY_SPECIFIC_DAY_TIME, specificDueDate.getMillis()));
}
@Test
public void testTaskHasDueTime() {
Task task = new Task();
task.setValue(DUE_DATE, 1388516076000L);
@ -102,6 +120,7 @@ public class TaskTest extends AndroidTestCase {
assertTrue(task.hasDueDate());
}
@Test
public void testTaskHasDueDate() {
Task task = new Task();
task.setValue(DUE_DATE, 1388469600000L);
@ -109,48 +128,58 @@ public class TaskTest extends AndroidTestCase {
assertTrue(task.hasDueDate());
}
@Test
public void testDoesHaveDueTime() {
assertTrue(hasDueTime(1388516076000L));
}
@Test
public void testNoDueTime() {
assertFalse(hasDueTime(newDateTime().startOfDay().getMillis()));
assertFalse(hasDueTime(newDateTime().withMillisOfDay(60000).getMillis()));
}
@Test
public void testHasDueTime() {
assertTrue(hasDueTime(newDateTime().withMillisOfDay(1).getMillis()));
assertTrue(hasDueTime(newDateTime().withMillisOfDay(1000).getMillis()));
assertTrue(hasDueTime(newDateTime().withMillisOfDay(59999).getMillis()));
}
@Test
public void testDoesNotHaveDueTime() {
assertFalse(hasDueTime(1388469600000L));
}
@Test
public void testNewTaskIsNotCompleted() {
assertFalse(new Task().isCompleted());
}
@Test
public void testNewTaskNotDeleted() {
assertFalse(new Task().isDeleted());
}
@Test
public void testNewTaskNotHidden() {
assertFalse(new Task().isHidden());
}
@Test
public void testNewTaskDoesNotHaveDueDateOrTime() {
assertFalse(new Task().hasDueDate());
assertFalse(new Task().hasDueTime());
}
@Test
public void testTaskIsCompleted() {
Task task = new Task();
task.setValue(COMPLETION_DATE, 1L);
assertTrue(task.isCompleted());
}
@Test
public void testTaskIsNotHiddenAtHideUntilTime() {
final long now = currentTimeMillis();
freezeAt(now).thawAfter(new Snippet() {{
@ -160,6 +189,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskIsHiddenBeforeHideUntilTime() {
final long now = currentTimeMillis();
freezeAt(now).thawAfter(new Snippet() {{
@ -169,16 +199,19 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskIsDeleted() {
Task task = new Task();
task.setValue(DELETION_DATE, 1L);
assertTrue(task.isDeleted());
}
@Test
public void testTaskWithNoDueDateIsOverdue() {
assertTrue(new Task().isOverdue());
}
@Test
public void testTaskNotOverdueAtDueTime() {
final long now = currentTimeMillis();
freezeAt(now).thawAfter(new Snippet() {{
@ -188,6 +221,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskIsOverduePastDueTime() {
final long dueDate = currentTimeMillis();
freezeAt(dueDate + 1).thawAfter(new Snippet() {{
@ -197,6 +231,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskNotOverdueBeforeNoonOnDueDate() {
final DateTime dueDate = new DateTime().startOfDay();
freezeAt(dueDate.plusHours(12).minusMillis(1)).thawAfter(new Snippet() {{
@ -207,6 +242,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskOverdueAtNoonOnDueDate() {
final DateTime dueDate = new DateTime().startOfDay();
freezeAt(dueDate.plusHours(12)).thawAfter(new Snippet() {{
@ -217,6 +253,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testTaskWithNoDueTimeIsOverdue() {
final DateTime dueDate = new DateTime().startOfDay();
freezeAt(dueDate.plusDays(1)).thawAfter(new Snippet() {{
@ -227,6 +264,7 @@ public class TaskTest extends AndroidTestCase {
}});
}
@Test
public void testSanity() {
assertTrue(Task.IMPORTANCE_DO_OR_DIE < Task.IMPORTANCE_MUST_DO);
assertTrue(Task.IMPORTANCE_MUST_DO < Task.IMPORTANCE_SHOULD_DO);

@ -1,34 +1,41 @@
package com.todoroo.astrid.model;
import android.content.ContentValues;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.data.Property;
import org.tasks.injection.InjectingTestCase;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Snippet;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
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)
public class TaskTest extends InjectingTestCase {
@Inject TaskService taskService;
@Inject Preferences preferences;
@Test
public void testNewTaskHasNoCreationDate() {
assertFalse(new Task().containsValue(Task.CREATION_DATE));
}
@Test
public void testSavedTaskHasCreationDate() {
freezeClock().thawAfter(new Snippet() {{
Task task = new Task();
@ -37,6 +44,7 @@ public class TaskTest extends InjectingTestCase {
}});
}
@Test
public void testReadTaskFromDb() {
Task task = new Task();
taskService.save(task);
@ -45,6 +53,7 @@ public class TaskTest extends InjectingTestCase {
compareRemoteModel(task, fromDb);
}
@Test
public void testDefaults() {
preferences.setDefaults();
ContentValues defaults = new Task().getDefaultValues();

@ -9,6 +9,7 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.andlib.data.Property.StringProperty;
@ -18,8 +19,16 @@ import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.fail;
@RunWith(AndroidJUnit4.class)
public class Astrid3ProviderTests extends DatabaseTestCase {
String[] PROJECTION = new String[] {
@ -28,7 +37,7 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
};
@Override
protected void setUp() {
public void setUp() {
super.setUp();
// set up database
@ -42,8 +51,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test CRUD over tasks with the ALL ITEMS cursor */
@Test
public void testAllItemsCrud() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
// fetch all tasks, get nothing
Uri uri = Task.CONTENT_URI;
@ -83,8 +93,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test selecting data */
@Test
public void testSelection() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
Uri uri = Task.CONTENT_URI;
// insert some tasks
@ -128,8 +139,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test updating */
@Test
public void testUpdating() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
// insert some tasks
ContentValues values = new ContentValues();
@ -191,8 +203,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test deleting */
@Test
public void testDeleting() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
Uri allItemsUri = Task.CONTENT_URI;
// insert some tasks
@ -250,8 +263,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test CRUD over SINGLE ITEM uri */
@Test
public void testSingleItemCrud() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
Uri uri = StoreObject.CONTENT_URI;
@ -295,8 +309,9 @@ public class Astrid3ProviderTests extends DatabaseTestCase {
}
/** Test GROUP BY uri */
@Test
public void testGroupByCrud() {
ContentResolver resolver = getContext().getContentResolver();
ContentResolver resolver = getTargetContext().getContentResolver();
Uri uri = Task.CONTENT_URI;
ContentValues values = new ContentValues();

@ -7,12 +7,15 @@ package com.todoroo.astrid.reminders;
import android.app.Notification;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Broadcaster;
import org.tasks.Notifier;
import org.tasks.injection.TestComponent;
@ -25,12 +28,14 @@ import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@RunWith(AndroidJUnit4.class)
public class NotificationTests extends DatabaseTestCase {
@Module
@ -70,13 +75,14 @@ public class NotificationTests extends DatabaseTestCase {
@Inject Notifier notifier;
@Override
protected void tearDown() {
public void tearDown() {
super.tearDown();
verifyNoMoreInteractions(notificationManager);
verifyNoMoreInteractions(broadcaster);
}
@Test
public void testAlarmToNotification() {
final Task task = new Task() {{
setTitle("rubberduck");
@ -90,6 +96,7 @@ public class NotificationTests extends DatabaseTestCase {
verify(notificationManager).notify(eq((int) task.getId()), any(Notification.class));
}
@Test
public void testDeletedTaskDoesntTriggerNotification() {
final Task task = new Task() {{
setTitle("gooeyduck");
@ -102,6 +109,7 @@ public class NotificationTests extends DatabaseTestCase {
verify(notificationManager).cancel((int) task.getId());
}
@Test
public void testCompletedTaskDoesntTriggerNotification() {
final Task task = new Task() {{
setTitle("rubberduck");
@ -179,7 +187,7 @@ public class NotificationTests extends DatabaseTestCase {
@Override
protected void inject(TestComponent component) {
component
.plus(new NotificationTestsModule(getContext()))
.plus(new NotificationTestsModule(getTargetContext()))
.inject(this);
}
}

@ -1,47 +1,58 @@
package com.todoroo.astrid.reminders;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.Task;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.preferences.Preferences;
import org.tasks.time.DateTime;
import static android.support.test.InstrumentationRegistry.getContext;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static com.natpryce.makeiteasy.MakeItEasy.with;
import static com.todoroo.astrid.data.Task.NOTIFY_AT_DEADLINE;
import static com.todoroo.astrid.reminders.ReminderService.NO_ALARM;
import static junit.framework.Assert.assertEquals;
import static org.tasks.makers.TaskMaker.DUE_DATE;
import static org.tasks.makers.TaskMaker.DUE_TIME;
import static org.tasks.makers.TaskMaker.REMINDERS;
import static org.tasks.makers.TaskMaker.REMINDER_LAST;
import static org.tasks.makers.TaskMaker.newTask;
public class NotifyAtDeadlineTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class NotifyAtDeadlineTest {
private ReminderService reminderService;
@Override
@Before
public void setUp() {
Preferences preferences = new Preferences(getContext(), null);
Preferences preferences = new Preferences(getTargetContext(), null);
reminderService = new ReminderService(getContext(), preferences, null);
}
@Test
public void testNoReminderWhenNoDueDate() {
Task task = newTask(with(REMINDERS, NOTIFY_AT_DEADLINE));
assertEquals(NO_ALARM, reminderService.calculateNextDueDateReminder(task));
}
@Test
public void testNoReminderWhenNotifyAtDeadlineFlagNotSet() {
Task task = newTask(with(DUE_TIME, new DateTime(2014, 1, 24, 19, 23)));
assertEquals(NO_ALARM, reminderService.calculateNextDueDateReminder(task));
}
@Test
public void testScheduleReminderAtDueTime() {
final DateTime dueDate = new DateTime(2014, 1, 24, 19, 23);
Task task = newTask(with(DUE_TIME, dueDate), with(REMINDERS, NOTIFY_AT_DEADLINE));
assertEquals(dueDate.plusSeconds(1).getMillis(), reminderService.calculateNextDueDateReminder(task));
}
@Test
public void testScheduleReminderAtDefaultDueTime() {
final DateTime dueDate = new DateTime(2015, 12, 29, 12, 0);
Task task = newTask(with(DUE_DATE, dueDate), with(REMINDERS, NOTIFY_AT_DEADLINE));
@ -49,6 +60,7 @@ public class NotifyAtDeadlineTest extends AndroidTestCase {
reminderService.calculateNextDueDateReminder(task));
}
@Test
public void testNoReminderIfAlreadyRemindedPastDueDate() {
final DateTime dueDate = new DateTime(2015, 12, 29, 19, 23);
Task task = newTask(

@ -6,21 +6,32 @@
package com.todoroo.astrid.reminders;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.ReminderService.AlarmScheduler;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import javax.inject.Inject;
import static android.support.test.InstrumentationRegistry.getContext;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.tasks.Freeze.freezeClock;
import static org.tasks.Freeze.thaw;
import static org.tasks.date.DateTimeUtils.newDateTime;
@RunWith(AndroidJUnit4.class)
public class ReminderServiceTest extends InjectingTestCase {
@Inject TaskDao taskDao;
@ -37,11 +48,12 @@ public class ReminderServiceTest extends InjectingTestCase {
component.inject(this);
}
@Override
@After
public void tearDown() {
thaw();
}
@Test
public void testNoReminders() {
reminderService.setScheduler(new NoAlarmExpected());
@ -53,13 +65,14 @@ public class ReminderServiceTest extends InjectingTestCase {
reminderService.scheduleAlarm(taskDao, task);
}
@Test
public void testDueDates() {
reminderService.setScheduler(new AlarmExpected() {
@Override
public void createAlarm(Context context, Task task, long time, int type) {
if (time == ReminderService.NO_ALARM)
return;
super.createAlarm(getContext(), task, time, type);
super.createAlarm(getTargetContext(), task, time, type);
assertEquals((long) task.getDueDate(), time);
assertEquals(type, ReminderService.TYPE_DUE);
}
@ -78,7 +91,9 @@ public class ReminderServiceTest extends InjectingTestCase {
assertTrue(((AlarmExpected) reminderService.getScheduler()).alarmCreated);
}
public void disabled_testRandom() {
@Ignore
@Test
public void testRandom() {
// test random
final Task task = new Task();
task.setTitle("water");
@ -98,6 +113,7 @@ public class ReminderServiceTest extends InjectingTestCase {
assertTrue(((AlarmExpected) reminderService.getScheduler()).alarmCreated);
}
@Test
public void testOverdue() {
// test due date in the future
reminderService.setScheduler(new AlarmExpected() {
@ -150,6 +166,7 @@ public class ReminderServiceTest extends InjectingTestCase {
assertTrue(((AlarmExpected) reminderService.getScheduler()).alarmCreated);
}
@Test
public void testMultipleReminders() {
// test due date in the future, enable random
final Task task = new Task();
@ -193,6 +210,7 @@ public class ReminderServiceTest extends InjectingTestCase {
assertTrue(((AlarmExpected) reminderService.getScheduler()).alarmCreated);
}
@Test
public void testSnoozeReminders() {
thaw(); // TODO: get rid of this

@ -5,7 +5,7 @@
*/
package com.todoroo.astrid.repeats;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
@ -14,15 +14,20 @@ import com.google.ical.values.WeekdayNum;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Task;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.time.DateTime;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import static junit.framework.Assert.assertEquals;
import static org.tasks.date.DateTimeUtils.newDateTime;
public class AdvancedRepeatTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class AdvancedRepeatTest {
private static final int PREV_PREV = -2;
private static final int PREV = -1;
@ -33,7 +38,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
private long nextDueDate;
private RRule rrule;
@Override
@Before
public void setUp() {
task = new Task();
task.setCompletionDate(DateUtilities.now());
@ -42,6 +47,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
// --- date with time tests
@Test
public void testDueDateSpecificTime() throws ParseException {
buildRRule(1, Frequency.DAILY);
@ -54,6 +60,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
assertDateTimeEquals(nextDayWithTime, nextDueDate);
}
@Test
public void testCompletionDateSpecificTime() throws ParseException {
buildRRule(1, Frequency.DAILY);
@ -76,6 +83,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
// --- due date tests
/** test multiple days per week - DUE DATE */
@Test
public void testDueDateInPastSingleWeekMultiDay() throws Exception {
buildRRule(1, Frequency.WEEKLY, Weekday.MO, Weekday.WE, Weekday.FR);
@ -93,6 +101,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
}
/** test single day repeats - DUE DATE */
@Test
public void testDueDateSingleDay() throws Exception {
buildRRule(1, Frequency.WEEKLY, Weekday.MO);
@ -122,6 +131,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
}
/** test multiple days per week - DUE DATE */
@Test
public void testDueDateSingleWeekMultiDay() throws Exception {
buildRRule(1, Frequency.WEEKLY, Weekday.MO, Weekday.WE, Weekday.FR);
@ -140,6 +150,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
}
/** test multiple days per week, multiple intervals - DUE DATE */
@Test
public void testDueDateMultiWeekMultiDay() throws Exception {
buildRRule(2, Frequency.WEEKLY, Weekday.MO, Weekday.WE, Weekday.FR);
@ -159,6 +170,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
// --- completion tests
/** test multiple days per week - COMPLETE DATE */
@Test
public void testCompleteDateSingleWeek() throws Exception {
for(Weekday wday : Weekday.values()) {
buildRRule(1, Frequency.WEEKLY, wday);
@ -184,6 +196,7 @@ public class AdvancedRepeatTest extends AndroidTestCase {
}
/** test multiple days per week, multiple intervals - COMPLETE DATE */
@Test
public void testCompleteDateMultiWeek() throws Exception {
for(Weekday wday : Weekday.values()) {
buildRRule(2, Frequency.WEEKLY, wday);

@ -6,6 +6,7 @@
package com.todoroo.astrid.repeats;
import android.content.Intent;
import android.support.test.runner.AndroidJUnit4;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
@ -21,6 +22,9 @@ import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
@ -32,15 +36,20 @@ import java.util.List;
import javax.inject.Inject;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.tasks.date.DateTimeUtils.newDateTime;
@RunWith(AndroidJUnit4.class)
public class NewRepeatTests extends DatabaseTestCase {
@Inject TaskDao taskDao;
@Inject Preferences preferences;
@Override
protected void setUp() {
public void setUp() {
super.setUp();
preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
}
@ -59,7 +68,7 @@ public class NewRepeatTests extends DatabaseTestCase {
Intent intent = new Intent(AstridApiConstants.BROADCAST_EVENT_TASK_COMPLETED);
intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, task.getId());
new RepeatTaskCompleteListener().onReceive(getContext(), intent);
new RepeatTaskCompleteListener().onReceive(getTargetContext(), intent);
}
protected void waitAndSync() {
@ -92,7 +101,9 @@ public class NewRepeatTests extends DatabaseTestCase {
* Tests for no sync
*/
public void disabled_testNoRepeat() {
@Ignore
@Test
public void testNoRepeat() {
Task t = new Task();
t.setTitle("no repeat");
taskDao.save(t);
@ -249,102 +260,150 @@ public class NewRepeatTests extends DatabaseTestCase {
/** Tests for repeating from due date */
public void disabled_testRepeatMinutelyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatMinutelyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.MINUTELY, "minutely-before");
}
public void disabled_testRepeatMinutelyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatMinutelyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.MINUTELY, "minutely-after");
}
public void disabled_testRepeatHourlyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatHourlyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.HOURLY, "hourly-before");
}
public void disabled_testRepeatHourlyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatHourlyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.HOURLY, "hourly-after");
}
public void disabled_testRepeatDailyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatDailyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.DAILY, "daily-before");
}
public void disabled_testRepeatDailyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatDailyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.DAILY, "daily-after");
}
public void disabled_testRepeatWeeklyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatWeeklyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.WEEKLY, "weekly-before");
}
public void disabled_testRepeatWeeklyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatWeeklyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.WEEKLY, "weekly-after");
}
public void disabled_testRepeatMonthlyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatMonthlyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.MONTHLY, "monthly-before");
}
public void disabled_testRepeatMonthlyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatMonthlyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.MONTHLY, "monthly-after");
}
public void disabled_testRepeatYearlyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testRepeatYearlyFromDueDateCompleteBefore() {
testFromDueDate(true, Frequency.YEARLY, "yearly-before");
}
public void disabled_testRepeatYearlyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testRepeatYearlyFromDueDateCompleteAfter() {
testFromDueDate(false, Frequency.YEARLY, "yearly-after");
}
/** Tests for repeating from completionDate */
public void disabled_testRepeatMinutelyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatMinutelyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.MINUTELY, "minutely-before");
}
public void disabled_testRepeatMinutelyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatMinutelyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.MINUTELY, "minutely-after");
}
public void disabled_testRepeatHourlyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatHourlyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.HOURLY, "hourly-before");
}
public void disabled_testRepeatHourlyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatHourlyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.HOURLY, "hourly-after");
}
public void disabled_testRepeatDailyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatDailyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.DAILY, "daily-before");
}
public void disabled_testRepeatDailyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatDailyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.DAILY, "daily-after");
}
public void disabled_testRepeatWeeklyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatWeeklyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.WEEKLY, "weekly-before");
}
public void disabled_testRepeatWeeklyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatWeeklyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.WEEKLY, "weekly-after");
}
public void disabled_testRepeatMonthlyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatMonthlyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.MONTHLY, "monthly-before");
}
public void disabled_testRepeatMonthlyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatMonthlyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.MONTHLY, "monthly-after");
}
public void disabled_testRepeatYearlyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testRepeatYearlyFromCompleteDateCompleteBefore() {
testFromCompletionDate(true, Frequency.YEARLY, "yearly-before");
}
public void disabled_testRepeatYearlyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testRepeatYearlyFromCompleteDateCompleteAfter() {
testFromCompletionDate(false, Frequency.YEARLY, "yearly-after");
}
@ -377,19 +436,27 @@ public class NewRepeatTests extends DatabaseTestCase {
// disabled until test can be fixed
public void disabled_testAdvancedRepeatWeeklyFromDueDateCompleteBefore() {
@Ignore
@Test
public void testAdvancedRepeatWeeklyFromDueDateCompleteBefore() {
testAdvancedWeeklyFromDueDate(true, "advanced-weekly-before");
}
public void disabled_testAdvancedRepeatWeeklyFromDueDateCompleteAfter() {
@Ignore
@Test
public void testAdvancedRepeatWeeklyFromDueDateCompleteAfter() {
testAdvancedWeeklyFromDueDate(false, "advanced-weekly-after");
}
public void disabled_testAdvancedRepeatWeeklyFromCompleteDateCompleteBefore() {
@Ignore
@Test
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteBefore() {
testAdvancedWeeklyFromCompleteDate(true, "advanced-weekly-before");
}
public void disabled_testAdvancedRepeatWeeklyFromCompleteDateCompleteAfter() {
@Ignore
@Test
public void testAdvancedRepeatWeeklyFromCompleteDateCompleteAfter() {
testAdvancedWeeklyFromCompleteDate(false, "advanced-weekly-after");
}
}

@ -1,12 +1,14 @@
package com.todoroo.astrid.repeats;
import android.annotation.SuppressLint;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.todoroo.astrid.data.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.time.DateTime;
import java.text.ParseException;
@ -21,9 +23,11 @@ import static com.todoroo.astrid.repeats.RepeatTaskCompleteListener.computeNextD
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.HOURS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static junit.framework.Assert.assertEquals;
@SuppressLint("NewApi")
public class RepeatTaskCompleteListenerTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class RepeatTaskCompleteListenerTest {
private final Task task = new Task();
private final long dueDate;
@ -36,34 +40,41 @@ public class RepeatTaskCompleteListenerTest extends AndroidTestCase {
task.setCompletionDate(completionDate);
}
@Test
public void testMinutelyRepeat() {
checkFrequency(6, MINUTES.toMillis(1), MINUTELY);
}
@Test
public void testHourlyRepeat() {
checkFrequency(6, HOURS.toMillis(1), HOURLY);
}
@Test
public void testDailyRepeat() {
checkFrequency(6, DAYS.toMillis(1), DAILY);
}
@Test
public void testWeeklyRepeat() {
checkFrequency(6, DAYS.toMillis(7), WEEKLY);
}
@Test
public void testMonthlyRepeat() {
assertEquals(
new DateTime(2014, 7, 7, 17, 17, 1, 0).getMillis(),
nextDueDate(6, Frequency.MONTHLY, true));
}
@Test
public void testMonthlyRepeatAtEndOfMonth() {
assertEquals(
new DateTime(2014, 6, 30, 17, 17, 1, 0).getMillis(),
nextDueDate(6, Frequency.MONTHLY, false));
}
@Test
public void testYearlyRepeat() {
checkExpected(6, addCalendarMonthsToUnixtime(dueDate, 6 * 12), YEARLY, false);
checkExpected(6, addCalendarMonthsToUnixtime(completionDate, 6 * 12), YEARLY, true);

@ -5,9 +5,13 @@
*/
package com.todoroo.astrid.service;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.ArrayList;
@ -16,20 +20,19 @@ import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class QuickAddMarkupTest extends DatabaseTestCase {
@Inject TaskService taskService;
@Override
protected void setUp() {
super.setUp();
}
@Override
protected void inject(TestComponent component) {
component.inject(this);
}
@Test
public void testTags() {
whenTitleIs("this #cool");
assertTitleBecomes("this");
@ -44,6 +47,7 @@ public class QuickAddMarkupTest extends DatabaseTestCase {
assertTagsAre("nice", "cute");
}
@Test
public void testContexts() {
whenTitleIs("eat @home");
assertTitleBecomes("eat");
@ -58,6 +62,7 @@ public class QuickAddMarkupTest extends DatabaseTestCase {
assertTagsAre();
}
@Test
public void testImportances() {
whenTitleIs("eat !1");
assertTitleBecomes("eat");
@ -71,6 +76,7 @@ public class QuickAddMarkupTest extends DatabaseTestCase {
assertImportanceIs(Task.IMPORTANCE_DO_OR_DIE);
}
@Test
public void testMixed() {
whenTitleIs("eat #food !2");
assertTitleBecomes("eat");

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.service;
import android.support.test.runner.AndroidJUnit4;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
import com.todoroo.astrid.data.Task;
@ -12,6 +14,9 @@ import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.test.DatabaseTestCase;
import com.todoroo.astrid.utility.TitleParser;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
@ -22,8 +27,13 @@ import java.util.Calendar;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertTrue;
import static org.tasks.date.DateTimeUtils.newDateTime;
@RunWith(AndroidJUnit4.class)
public class TitleParserTest extends DatabaseTestCase {
@Inject TaskService taskService;
@ -31,7 +41,7 @@ public class TitleParserTest extends DatabaseTestCase {
@Inject Preferences preferences;
@Override
protected void setUp() {
public void setUp() {
super.setUp();
preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
}
@ -42,6 +52,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
/** test that completing a task w/ no regular expressions creates a simple task with no date, no repeat, no lists*/
@Test
public void testNoRegexes() throws Exception{
Task task = new Task();
Task nothing = new Task();
@ -53,6 +64,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
/** Tests correct date is parsed **/
@Test
public void testMonthDate() {
Task task = new Task();
String[] titleMonthStrings = {
@ -78,6 +90,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testMonthSlashDay() {
Task task = new Task();
for (int i = 1; i < 13; i++) {
@ -90,6 +103,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testArmyTime() {
Task task = new Task();
String testTitle = "Jog on 23:21.";
@ -99,6 +113,7 @@ public class TitleParserTest extends DatabaseTestCase {
assertEquals(date.getMinuteOfHour(), 21);
}
@Test
public void test_AM_PM() {
Task task = new Task();
String testTitle = "Jog at 8:33 PM.";
@ -108,6 +123,7 @@ public class TitleParserTest extends DatabaseTestCase {
assertEquals(date.getMinuteOfHour(), 33);
}
@Test
public void test_at_hour() {
Task task = new Task();
String testTitle = "Jog at 8 PM.";
@ -117,6 +133,7 @@ public class TitleParserTest extends DatabaseTestCase {
assertEquals(date.getMinuteOfHour(), 0);
}
@Test
public void test_oclock_AM() {
Task task = new Task();
String testTitle = "Jog at 8 o'clock AM.";
@ -126,6 +143,7 @@ public class TitleParserTest extends DatabaseTestCase {
assertEquals(date.getMinuteOfHour(), 0);
}
@Test
public void test_several_forms_of_eight() {
Task task = new Task();
String[] testTitles = {
@ -141,6 +159,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void test_several_forms_of_1230PM() {
Task task = new Task();
String[] testTitles = {
@ -166,7 +185,9 @@ public class TitleParserTest extends DatabaseTestCase {
// ----------------Days begin----------------//
public void disabled_testDays() {
@Ignore
@Test
public void testDays() {
Calendar today = Calendar.getInstance();
Task task = new Task();
@ -226,6 +247,7 @@ public class TitleParserTest extends DatabaseTestCase {
//----------------Priority begin----------------//
/** tests all words using priority 0 */
@Test
public void testPriority0() throws Exception {
String[] acceptedStrings = {
"priority 0",
@ -250,6 +272,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testPriority1() throws Exception {
String[] acceptedStringsAtEnd = {
"priority 1",
@ -286,6 +309,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testPriority2() throws Exception {
String[] acceptedStringsAtEnd = {
"priority 2",
@ -325,6 +349,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testPriority3() throws Exception {
String[] acceptedStringsAtEnd = {
"priority 3",
@ -367,13 +392,12 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
//----------------Priority end----------------//
//----------------Repeats begin----------------//
/** test daily repeat from due date, but with no due date set */
@Test
public void testDailyWithNoDueDate() throws Exception {
Task task = new Task();
String title = "Jog daily";
@ -407,6 +431,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
/** test weekly repeat from due date, with no due date & time set */
@Test
public void testWeeklyWithNoDueDate() throws Exception {
Task task = new Task();
String title = "Jog weekly";
@ -439,6 +464,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
/** test hourly repeat from due date, with no due date but no time */
@Test
public void testMonthlyFromNoDueDate() throws Exception {
Task task = new Task();
String title = "Jog monthly";
@ -470,6 +496,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testDailyFromDueDate() throws Exception {
Task task = new Task();
String title = "Jog daily starting from today";
@ -500,6 +527,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
}
@Test
public void testWeeklyFromDueDate() throws Exception {
Task task = new Task();
String title = "Jog weekly starting from today";
@ -535,6 +563,7 @@ public class TitleParserTest extends DatabaseTestCase {
//----------------Tags begin----------------//
/** tests all words using priority 0 */
@Test
public void testTagsPound() throws Exception {
String[] acceptedStrings = {
"#tag",
@ -554,6 +583,7 @@ public class TitleParserTest extends DatabaseTestCase {
}
/** tests all words using priority 0 */
@Test
public void testTagsAt() throws Exception {
String[] acceptedStrings = {
"@tag",
@ -571,10 +601,4 @@ public class TitleParserTest extends DatabaseTestCase {
assertTrue("testTagsAt failed for string: " + acceptedString+ " for tags: " + tags.toString(), tags.contains(tag));
}
}
//----------------Priority end----------------//
}

@ -1,19 +1,27 @@
package com.todoroo.astrid.subtasks;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.service.TaskService;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class SubtasksHelperTest extends SubtasksTestCase {
@Inject TaskService taskService;
@Override
protected void setUp() {
public void setUp() {
super.setUp();
createTasks();
TaskListMetadata m = new TaskListMetadata();
@ -39,6 +47,7 @@ public class SubtasksHelperTest extends SubtasksTestCase {
private static final String[] EXPECTED_ORDER = { "-1", "1", "2", "3", "4", "5", "6" };
@Test
public void testOrderedIdArray() {
String[] ids = SubtasksHelper.getStringIdArray(DEFAULT_SERIALIZED_TREE);
assertEquals(EXPECTED_ORDER.length, ids.length);
@ -50,7 +59,9 @@ public class SubtasksHelperTest extends SubtasksTestCase {
// Default order: "[-1, [1, 2, [3, 4]], 5, 6]"
private static String EXPECTED_REMOTE = "[\"-1\", [\"6\", \"4\", [\"3\", \"1\"]], \"2\", \"5\"]".replaceAll("\\s", "");
public void disabled_testLocalToRemoteIdMapping() {
@Ignore
@Test
public void testLocalToRemoteIdMapping() {
String mapped = SubtasksHelper.convertTreeToRemoteIds(taskService, DEFAULT_SERIALIZED_TREE).replaceAll("\\s", "");
assertEquals(EXPECTED_REMOTE, mapped);
}

@ -1,11 +1,18 @@
package com.todoroo.astrid.subtasks;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.service.TaskService;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.inject.Inject;
@RunWith(AndroidJUnit4.class)
public class SubtasksMovingTest extends SubtasksTestCase {
@Inject TaskService taskService;
@ -60,7 +67,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
* F
*/
public void disabled_testMoveBeforeIntoSelf() { // Should have no effect
@Ignore
@Test
public void testMoveBeforeIntoSelf() { // Should have no effect
whenTriggerMoveBefore(A, B);
expectParentAndPosition(A, null, 0);
@ -71,7 +80,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
expectParentAndPosition(F, null, 2);
}
public void disabled_testMoveIntoDescendant() { // Should have no effect
@Ignore
@Test
public void testMoveIntoDescendant() { // Should have no effect
whenTriggerMoveBefore(A, C);
expectParentAndPosition(A, null, 0);
@ -82,7 +93,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
expectParentAndPosition(F, null, 2);
}
public void disabled_testMoveToEndOfChildren() { // Should have no effect
@Ignore
@Test
public void testMoveToEndOfChildren() { // Should have no effect
whenTriggerMoveBefore(A, E);
expectParentAndPosition(A, null, 0);
@ -93,7 +106,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
expectParentAndPosition(F, null, 2);
}
public void disabled_testStandardMove() {
@Ignore
@Test
public void testStandardMove() {
whenTriggerMoveBefore(A, F);
expectParentAndPosition(A, null, 1);
@ -104,7 +119,9 @@ public class SubtasksMovingTest extends SubtasksTestCase {
expectParentAndPosition(F, null, 2);
}
public void disabled_testMoveToEndOfList() {
@Ignore
@Test
public void testMoveToEndOfList() {
whenTriggerMoveBefore(A, null);
expectParentAndPosition(A, null, 2);

@ -14,6 +14,10 @@ import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
/**
* Contains useful methods common to all subtasks tests
* @author Sam
@ -40,9 +44,9 @@ public class SubtasksTestCase extends DatabaseTestCase {
public static final String DEFAULT_SERIALIZED_TREE = "[-1, [1, 2, [3, 4]], 5, 6]".replaceAll("\\s", "");
@Override
protected void setUp() {
public void setUp() {
super.setUp();
filter = BuiltInFilterExposer.getMyTasksFilter(getContext().getResources());
filter = BuiltInFilterExposer.getMyTasksFilter(getTargetContext().getResources());
preferences.clear(SubtasksUpdater.ACTIVE_TASKS_ORDER);
updater = new SubtasksFilterUpdater(taskListMetadataDao, taskService);
}

@ -1,16 +1,26 @@
package com.todoroo.astrid.sync;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import static junit.framework.Assert.assertFalse;
@RunWith(AndroidJUnit4.class)
public class SyncModelTest extends NewSyncTestCase {
@Test
public void testCreateTaskMakesUuid() {
Task task = createTask();
assertFalse(RemoteModel.NO_UUID.equals(task.getUUID()));
}
@Test
public void testCreateTagMakesUuid() {
TagData tag = createTagData();
assertFalse(RemoteModel.NO_UUID.equals(tag.getUUID()));

@ -6,13 +6,20 @@
package com.todoroo.astrid.test;
import android.content.res.Resources;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.test.TranslationTests;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import java.util.Locale;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class AstridTranslationTest extends TranslationTests {
@Override
@ -49,8 +56,9 @@ public class AstridTranslationTest extends TranslationTests {
/**
* Test dollar sign resources
*/
@Test
public void testSpecialStringsMatch() throws Exception {
final Resources r = getContext().getResources();
final Resources r = getTargetContext().getResources();
final StringBuilder failures = new StringBuilder();
forEachLocale(() -> {

@ -7,25 +7,28 @@ package com.todoroo.astrid.test;
import com.todoroo.astrid.dao.Database;
import org.junit.After;
import org.tasks.injection.InjectingTestCase;
import static android.support.test.InstrumentationRegistry.getTargetContext;
public abstract class DatabaseTestCase extends InjectingTestCase {
protected Database database;
@Override
protected void setUp() {
public void setUp() {
super.setUp();
database = component.getDatabase();
database.close();
getContext().deleteDatabase(database.getName());
getTargetContext().deleteDatabase(database.getName());
database.openForWriting();
}
@Override
protected void tearDown() {
@After
public void tearDown() {
database.close();
}
}

@ -1,32 +1,39 @@
package org.tasks.date;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Snippet;
import org.tasks.time.DateTime;
import java.util.TimeZone;
import static junit.framework.Assert.assertEquals;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.date.DateTimeUtils.newDateUtc;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
public class DateTimeUtilsTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class DateTimeUtilsTest {
private final DateTime now = new DateTime(2014, 1, 1, 15, 17, 53, 0);
@Test
public void testGetCurrentTime() {
freezeAt(now).thawAfter(new Snippet() {{
assertEquals(now.getMillis(), currentTimeMillis());
}});
}
@Test
public void testCreateNewUtcDate() {
DateTime utc = now.toUTC();
DateTime actual = newDateUtc(utc.getYear(), utc.getMonthOfYear(), utc.getDayOfMonth(), utc.getHourOfDay(), utc.getMinuteOfHour(), utc.getSecondOfMinute());
assertEquals(utc.getMillis(), actual.getMillis());
}
@Test
public void testIllegalInstant() {
new DateTime(2015, 7, 24, 0, 0, 0, 0, TimeZone.getTimeZone("Africa/Cairo"));
new DateTime(2015, 10, 18, 0, 0, 0, 0, TimeZone.getTimeZone("America/Sao_Paulo"));

@ -1,19 +1,20 @@
package org.tasks.injection;
import android.test.AndroidTestCase;
import org.junit.Before;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static org.tasks.TestUtilities.initializeMockito;
public abstract class InjectingTestCase extends AndroidTestCase {
public abstract class InjectingTestCase {
protected TestComponent component;
@Override
protected void setUp() {
initializeMockito(getContext());
@Before
public void setUp() {
initializeMockito(getTargetContext());
component = DaggerTestComponent.builder()
.testModule(new TestModule(getContext()))
.testModule(new TestModule(getTargetContext()))
.build();
inject(component);
}

@ -1,15 +1,22 @@
package org.tasks.scheduling;
import android.annotation.SuppressLint;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import org.tasks.preferences.Preferences;
import org.tasks.time.DateTime;
import java.util.concurrent.TimeUnit;
public class AlarmManagerTests extends AndroidTestCase {
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class AlarmManagerTests {
@SuppressLint("NewApi")
private static final int MILLIS_PER_HOUR = (int) TimeUnit.HOURS.toMillis(1);
@ -17,14 +24,15 @@ public class AlarmManagerTests extends AndroidTestCase {
private Preferences preferences;
private AlarmManager alarmManager;
@Override
@Before
public void setUp() {
preferences = new Preferences(getContext(), null);
preferences = new Preferences(getTargetContext(), null);
preferences.clear();
preferences.setBoolean(R.string.p_rmd_enable_quiet, true);
alarmManager = new AlarmManager(getContext(), preferences);
alarmManager = new AlarmManager(getTargetContext(), preferences);
}
@Test
public void testNotQuietWhenQuietHoursDisabled() {
preferences.setBoolean(R.string.p_rmd_enable_quiet, false);
setQuietHoursStart(22);
@ -35,6 +43,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsQuietAtStartOfQuietHoursNoWrap() {
setQuietHoursStart(18);
setQuietHoursEnd(19);
@ -45,6 +54,7 @@ public class AlarmManagerTests extends AndroidTestCase {
alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsQuietAtStartOfQuietHoursWrap() {
setQuietHoursStart(22);
setQuietHoursEnd(10);
@ -55,6 +65,7 @@ public class AlarmManagerTests extends AndroidTestCase {
alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testAdjustForQuietHoursNightWrap() {
setQuietHoursStart(22);
setQuietHoursEnd(10);
@ -65,6 +76,7 @@ public class AlarmManagerTests extends AndroidTestCase {
alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testAdjustForQuietHoursMorningWrap() {
setQuietHoursStart(22);
setQuietHoursEnd(10);
@ -75,6 +87,7 @@ public class AlarmManagerTests extends AndroidTestCase {
alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testAdjustForQuietHoursWhenStartAndEndAreSame() {
setQuietHoursStart(18);
setQuietHoursEnd(18);
@ -84,6 +97,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsNotQuietAtEndOfQuietHoursNoWrap() {
setQuietHoursStart(17);
setQuietHoursEnd(18);
@ -93,6 +107,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsNotQuietAtEndOfQuietHoursWrap() {
setQuietHoursStart(22);
setQuietHoursEnd(10);
@ -102,6 +117,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsNotQuietBeforeNoWrap() {
setQuietHoursStart(17);
setQuietHoursEnd(18);
@ -111,6 +127,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsNotQuietAfterNoWrap() {
setQuietHoursStart(17);
setQuietHoursEnd(18);
@ -120,6 +137,7 @@ public class AlarmManagerTests extends AndroidTestCase {
assertEquals(dueDate, alarmManager.adjustForQuietHours(dueDate));
}
@Test
public void testIsNotQuietWrap() {
setQuietHoursStart(22);
setQuietHoursEnd(10);

@ -5,12 +5,17 @@
*/
package org.tasks.scheduling;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.backup.TasksXmlExporter;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
@ -20,9 +25,14 @@ import java.io.IOException;
import javax.inject.Inject;
import static android.support.test.InstrumentationRegistry.getContext;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.tasks.date.DateTimeUtils.newDateTime;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
@RunWith(AndroidJUnit4.class)
public class BackupServiceTests extends DatabaseTestCase {
private static final long BACKUP_WAIT_TIME = 500L;
@ -34,7 +44,7 @@ public class BackupServiceTests extends DatabaseTestCase {
@Inject Preferences preferences;
@Override
protected void setUp() {
public void setUp() {
super.setUp();
try {
@ -62,7 +72,7 @@ public class BackupServiceTests extends DatabaseTestCase {
}
@Override
protected void tearDown() {
public void tearDown() {
super.tearDown();
if (temporaryDirectory != null) {
@ -72,7 +82,9 @@ public class BackupServiceTests extends DatabaseTestCase {
}
}
public void disabled_testBackup() {
@Ignore
@Test
public void testBackup() {
assertEquals(0, temporaryDirectory.list().length);
preferences.setLong(TasksXmlExporter.PREF_BACKUP_LAST_DATE, 0);
@ -92,6 +104,7 @@ public class BackupServiceTests extends DatabaseTestCase {
assertTrue(preferences.getLong(TasksXmlExporter.PREF_BACKUP_LAST_DATE, 0) > 0);
}
@Test
public void testDeletion() throws IOException {
// create a bunch of backups
assertEquals(0, temporaryDirectory.list().length);

@ -1,24 +1,34 @@
package org.tasks.time;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.Freeze;
import org.tasks.Snippet;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
public class DateTimeTest extends AndroidTestCase {
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
public class DateTimeTest {
@Test
public void testGetMillisOfDay() {
assertEquals(7248412, new DateTime(2015, 10, 6, 2, 0, 48, 412).getMillisOfDay());
}
@Test
public void testWithMillisOfDay() {
assertEquals(
new DateTime(2015, 10, 6, 2, 0, 48, 412),
new DateTime(2015, 10, 6, 0, 0, 0, 0).withMillisOfDay(7248412));
}
@Test
public void testWithMillisOfDayDuringDST() {
TimeZone def = TimeZone.getDefault();
try {
@ -29,6 +39,7 @@ public class DateTimeTest extends AndroidTestCase {
}
}
@Test
public void testWithMillisOfDayAfterDST() {
TimeZone def = TimeZone.getDefault();
try {
@ -39,6 +50,7 @@ public class DateTimeTest extends AndroidTestCase {
}
}
@Test
public void testWithMillisOfDayStartDST() {
TimeZone def = TimeZone.getDefault();
try {
@ -56,6 +68,7 @@ public class DateTimeTest extends AndroidTestCase {
}
}
@Test
public void testWithMillisOfDayEndDST() {
TimeZone def = TimeZone.getDefault();
try {
@ -68,38 +81,45 @@ public class DateTimeTest extends AndroidTestCase {
}
}
@Test
public void testPlusMonths() {
assertEquals(
new DateTime(2015, 11, 6, 2, 0, 48, 412),
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(1));
}
@Test
public void testPlusMonthsWrapYear() {
assertEquals(
new DateTime(2016, 1, 6, 2, 0, 48, 412),
new DateTime(2015, 10, 6, 2, 0, 48, 412).plusMonths(3));
}
@Test
public void testGetDayOfMonth() {
assertEquals(5, new DateTime(2015, 10, 5, 0, 0, 0).getDayOfMonth());
}
@Test
public void testPlusDays() {
assertEquals(
new DateTime(2015, 10, 6, 2, 0, 48, 412),
new DateTime(2015, 10, 5, 2, 0, 48, 412).plusDays(1));
}
@Test
public void testPlusDaysWrapMonth() {
assertEquals(
new DateTime(2015, 11, 1, 2, 0, 48, 412),
new DateTime(2015, 10, 31, 2, 0, 48, 412).plusDays(1));
}
@Test
public void testMinuteOfHour() {
assertEquals(43, new DateTime(2015, 10, 5, 2, 43, 48).getMinuteOfHour());
}
@Test
public void testIsEndOfMonth() {
assertTrue(new DateTime(2014, 1, 31, 0, 0, 0).isLastDayOfMonth());
assertTrue(new DateTime(2014, 2, 28, 0, 0, 0).isLastDayOfMonth());
@ -115,6 +135,7 @@ public class DateTimeTest extends AndroidTestCase {
assertTrue(new DateTime(2014, 12, 31, 0, 0, 0).isLastDayOfMonth());
}
@Test
public void testNotTheEndOfTheMonth() {
for (int month = 1; month <= 12; month++) {
int lastDay = new DateTime(2014, month, 1, 0, 0, 0, 0).getNumberOfDaysInMonth();
@ -124,12 +145,13 @@ public class DateTimeTest extends AndroidTestCase {
}
}
@Test
public void testCheckEndOfMonthDuringLeapYear() {
assertFalse(new DateTime(2016, 2, 28, 0, 0, 0).isLastDayOfMonth());
assertTrue(new DateTime(2016, 2, 29, 0, 0, 0).isLastDayOfMonth());
}
@Test
public void testNumberOfDaysInMonth() {
assertEquals(31, new DateTime(2015, 1, 5, 9, 45, 34).getNumberOfDaysInMonth());
assertEquals(28, new DateTime(2015, 2, 5, 9, 45, 34).getNumberOfDaysInMonth());
@ -145,40 +167,47 @@ public class DateTimeTest extends AndroidTestCase {
assertEquals(31, new DateTime(2015, 12, 5, 9, 45, 34).getNumberOfDaysInMonth());
}
@Test
public void testWithMillisOfSecond() {
assertEquals(
new DateTime(2015, 11, 6, 13, 34, 56, 453),
new DateTime(2015, 11, 6, 13, 34, 56, 0).withMillisOfSecond(453));
}
@Test
public void testWithHourOfDay() {
assertEquals(
new DateTime(2015, 11, 6, 23, 0, 0),
new DateTime(2015, 11, 6, 1, 0, 0).withHourOfDay(23));
}
@Test
public void testWithMinuteOfHour() {
assertEquals(
new DateTime(2015, 11, 6, 23, 13, 0),
new DateTime(2015, 11, 6, 23, 1, 0).withMinuteOfHour(13));
}
@Test
public void testWithSecondOfMinute() {
assertEquals(
new DateTime(2015, 11, 6, 23, 13, 56),
new DateTime(2015, 11, 6, 23, 13, 1).withSecondOfMinute(56));
}
@Test
public void testGetYear() {
assertEquals(2015, new DateTime(2015, 1, 1, 1, 1, 1).getYear());
}
@Test
public void testMinusMinutes() {
assertEquals(
new DateTime(2015, 11, 4, 23, 59, 0),
new DateTime(2015, 11, 5, 0, 1, 0).minusMinutes(2));
}
@Test
public void testIsBefore() {
assertTrue(new DateTime(2015, 11, 4, 23, 59, 0)
.isBefore(new DateTime(2015, 11, 4, 23, 59, 1)));
@ -187,10 +216,12 @@ public class DateTimeTest extends AndroidTestCase {
.isBefore(new DateTime(2015, 11, 4, 23, 59, 0)));
}
@Test
public void testGetMonthOfYear() {
assertEquals(1, new DateTime(2015, 1, 2, 3, 4, 5).getMonthOfYear());
}
@Test
public void testIsAfter() {
assertTrue(new DateTime(2015, 11, 4, 23, 59, 1)
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
@ -199,46 +230,54 @@ public class DateTimeTest extends AndroidTestCase {
.isAfter(new DateTime(2015, 11, 4, 23, 59, 0)));
}
@Test
public void testWithYear() {
assertEquals(
new DateTime(2016, 1, 1, 1, 1, 1),
new DateTime(2015, 1, 1, 1, 1, 1).withYear(2016));
}
@Test
public void testWithMonthOfYear() {
assertEquals(
new DateTime(2015, 1, 2, 3, 4, 5),
new DateTime(2015, 2, 2, 3, 4, 5).withMonthOfYear(1));
}
@Test
public void testGetHourOfDay() {
assertEquals(3, new DateTime(2015, 1, 2, 3, 4, 5).getHourOfDay());
}
@Test
public void testWithDayOfMonth() {
assertEquals(
new DateTime(2015, 1, 2, 3, 4, 5),
new DateTime(2015, 1, 1, 3, 4, 5).withDayOfMonth(2));
}
@Test
public void testPlusMinutes() {
assertEquals(
new DateTime(2015, 1, 2, 3, 4, 5),
new DateTime(2015, 1, 2, 2, 59, 5).plusMinutes(5));
}
@Test
public void testPlusHours() {
assertEquals(
new DateTime(2015, 1, 2, 3, 4, 5),
new DateTime(2015, 1, 1, 3, 4, 5).plusHours(24));
}
@Test
public void testPlusWeeks() {
assertEquals(
new DateTime(2015, 1, 2, 3, 4, 5),
new DateTime(2014, 12, 12, 3, 4, 5).plusWeeks(3));
}
@Test
public void testIsBeforeNow() {
Freeze.freezeAt(new DateTime(2015, 10, 6, 16, 15, 27)).thawAfter(new Snippet() {{
assertFalse(new DateTime(2015, 10, 6, 16, 15, 27).isBeforeNow());
@ -246,12 +285,14 @@ public class DateTimeTest extends AndroidTestCase {
}});
}
@Test
public void testMinusMillis() {
assertEquals(
new DateTime(2015, 11, 6, 16, 18, 20, 452),
new DateTime(2015, 11, 6, 16, 18, 21, 374).minusMillis(922));
}
@Test
public void testMinusDays() {
assertEquals(
new DateTime(2015, 11, 6, 16, 19, 16),
@ -262,10 +303,12 @@ public class DateTimeTest extends AndroidTestCase {
new DateTime(2015, 11, 7, 16, 19, 16).minusDays(1));
}
@Test
public void testGetSecondOfMinute() {
assertEquals(32, new DateTime(2015, 11, 6, 16, 19, 32).getSecondOfMinute());
}
@Test
public void testToUTC() {
TimeZone def = TimeZone.getDefault();
try {

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.gtasks;
import android.support.test.runner.AndroidJUnit4;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.data.Metadata;
@ -12,6 +14,9 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.ArrayList;
@ -19,7 +24,11 @@ import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
@SuppressWarnings("nls")
@RunWith(AndroidJUnit4.class)
public class GtasksIndentActionTest extends DatabaseTestCase {
@Inject GtasksListService gtasksListService;
@ -31,6 +40,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
private Task task;
private GtasksList storeList;
@Test
public void testIndentWithoutMetadata() {
givenTask(taskWithoutMetadata());
@ -39,6 +49,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
// should not crash
}
@Test
public void disabled_testIndentWithMetadataButNoOtherTasks() {
givenTask(taskWithMetadata(0, 0));
@ -47,6 +58,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(0);
}
@Test
public void testIndentWithMetadata() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
@ -56,6 +68,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(1);
}
@Test
public void testDeindentWithMetadata() {
givenTask(taskWithMetadata(0, 1));
@ -64,6 +77,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(0);
}
@Test
public void testDeindentWithoutMetadata() {
givenTask(taskWithoutMetadata());
@ -72,6 +86,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
// should not crash
}
@Test
public void testDeindentWhenAlreadyZero() {
givenTask(taskWithMetadata(0, 0));
@ -80,7 +95,9 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(0);
}
public void disabled_testIndentWithChildren() {
@Ignore
@Test
public void testIndentWithChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
Task child = taskWithMetadata(2, 1);
@ -91,6 +108,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(child, 2);
}
@Test
public void testDeindentWithChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 1));
@ -102,6 +120,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(child, 1);
}
@Test
public void testIndentWithSiblings() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
@ -113,7 +132,9 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
thenExpectIndentationLevel(sibling, 0);
}
public void disabled_testIndentWithChildrensChildren() {
@Ignore
@Test
public void testIndentWithChildrensChildren() {
taskWithMetadata(0, 0);
givenTask(taskWithMetadata(1, 0));
Task child = taskWithMetadata(2, 1);
@ -137,7 +158,7 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
}
@Override
protected void setUp() {
public void setUp() {
super.setUp();
List<TaskList> items = new ArrayList<>();
@ -188,5 +209,4 @@ public class GtasksIndentActionTest extends DatabaseTestCase {
taskService.save(task);
return task;
}
}//*/
}

@ -1,11 +1,15 @@
package com.todoroo.astrid.gtasks;
import android.support.test.runner.AndroidJUnit4;
import com.google.api.client.util.DateTime;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import org.tasks.makers.RemoteGtaskListMaker;
@ -13,6 +17,8 @@ import javax.inject.Inject;
import static com.natpryce.makeiteasy.MakeItEasy.with;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.tasks.time.DateTimeUtils.currentTimeMillis;
@ -22,6 +28,7 @@ import static org.tasks.makers.GtaskListMaker.REMOTE_ID;
import static org.tasks.makers.GtaskListMaker.newGtaskList;
import static org.tasks.makers.RemoteGtaskListMaker.newRemoteList;
@RunWith(AndroidJUnit4.class)
public class GtasksListServiceTest extends DatabaseTestCase {
@Inject Database database;
@ -41,6 +48,7 @@ public class GtasksListServiceTest extends DatabaseTestCase {
component.inject(this);
}
@Test
public void testCreateNewList() {
setLists(newRemoteList(
with(RemoteGtaskListMaker.REMOTE_ID, "1"),
@ -51,6 +59,7 @@ public class GtasksListServiceTest extends DatabaseTestCase {
with(NAME, "Default")));
}
@Test
public void testGetListByRemoteId() {
GtasksList list = newGtaskList(with(REMOTE_ID, "1"));
storeObjectDao.createNew(list.getStoreObject());
@ -58,10 +67,12 @@ public class GtasksListServiceTest extends DatabaseTestCase {
assertEquals(list, gtasksListService.getList("1"));
}
@Test
public void testGetListReturnsNullWhenNotFound() {
assertNull(gtasksListService.getList("1"));
}
@Test
public void testDeleteMissingList() {
storeObjectDao.createNew(newGtaskList(with(REMOTE_ID, "1")).getStoreObject());
@ -70,6 +81,7 @@ public class GtasksListServiceTest extends DatabaseTestCase {
verify(storeObjectDao).delete(1L);
}
@Test
public void testUpdateListName() {
storeObjectDao.createNew(newGtaskList(
with(REMOTE_ID, "1"),
@ -82,12 +94,14 @@ public class GtasksListServiceTest extends DatabaseTestCase {
assertEquals("newName", storeObjectDao.getGtasksList(1).getName());
}
@Test
public void testNewListLastSyncIsZero() {
setLists(new TaskList().setId("1"));
assertEquals(0L, gtasksListService.getList("1").getLastSync());
}
@Test
public void testNewListNeedsUpdate() {
TaskList taskList = new TaskList().setId("1").setTitle("Default").setUpdated(new DateTime(currentTimeMillis()));

@ -6,6 +6,7 @@
package com.todoroo.astrid.gtasks;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.data.Metadata;
@ -13,6 +14,8 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
@ -22,7 +25,12 @@ import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
@SuppressWarnings("nls")
@RunWith(AndroidJUnit4.class)
public class GtasksMetadataServiceTest extends DatabaseTestCase {
@Module
@ -69,10 +77,11 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
@Override
protected void inject(TestComponent component) {
component
.plus(new GtasksMetadataServiceTestModule(getContext()))
.plus(new GtasksMetadataServiceTestModule(getTargetContext()))
.inject(this);
}
@Test
public void testMetadataFound() {
givenTask(taskWithMetadata(null));
@ -81,6 +90,7 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
thenExpectMetadataFound();
}
@Test
public void testMetadataDoesntExist() {
givenTask(taskWithoutMetadata());

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.gtasks;
import android.support.test.runner.AndroidJUnit4;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.data.Metadata;
@ -12,6 +14,9 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.ArrayList;
@ -19,7 +24,11 @@ import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
@SuppressWarnings("nls")
@RunWith(AndroidJUnit4.class)
public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
private static final int VALUE_UNSET = -1;
@ -30,6 +39,7 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
@Inject TaskService taskService;
@Inject GtasksMetadata gtasksMetadata;
@Test
public void testBasicParentComputation() {
Task[] tasks = givenTasksABCDE();
@ -42,7 +52,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
thenExpectParent(tasks[4], null);
}
public void disabled_testBasicSiblingComputation() {
@Ignore
@Test
public void testBasicSiblingComputation() {
Task[] tasks = givenTasksABCDE();
whenCalculatingParentsAndSiblings();
@ -54,7 +66,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
thenExpectSibling(tasks[4], tasks[0]);
}
public void disabled_testMetadataParentComputation() {
@Ignore
@Test
public void testMetadataParentComputation() {
Task[] tasks = givenTasksABCDE();
thenExpectMetadataParent(tasks[0], null);
@ -64,7 +78,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
thenExpectMetadataParent(tasks[4], null);
}
public void disabled_testMetadataOrderComputation() {
@Ignore
@Test
public void testMetadataOrderComputation() {
Task[] tasks = givenTasksABCDE();
thenExpectMetadataIndentAndOrder(tasks[0], 0, 0);
@ -74,7 +90,9 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
thenExpectMetadataIndentAndOrder(tasks[4], 4, 0);
}
public void disabled_testNewTaskOrder() {
@Ignore
@Test
public void testNewTaskOrder() {
givenTasksABCDE();
Task newTask = createTask("F", VALUE_UNSET, 0);
@ -121,7 +139,7 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
}
@Override
protected void setUp() {
public void setUp() {
super.setUp();
List<TaskList> items = new ArrayList<>();
@ -178,5 +196,4 @@ public class GtasksTaskListUpdaterTest extends DatabaseTestCase {
metadataDao.persist(metadata);
return task;
}
}//*/
}

@ -5,6 +5,8 @@
*/
package com.todoroo.astrid.gtasks;
import android.support.test.runner.AndroidJUnit4;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.data.Metadata;
@ -12,6 +14,9 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.TestComponent;
import java.util.ArrayList;
@ -19,7 +24,11 @@ import java.util.List;
import javax.inject.Inject;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
@SuppressWarnings("nls")
@RunWith(AndroidJUnit4.class)
public class GtasksTaskMovingTest extends DatabaseTestCase {
private static final int VALUE_UNSET = -1;
@ -43,7 +52,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
* F
*/
public void disabled_testMoveDownFromListBottom() {
@Ignore
@Test
public void testMoveDownFromListBottom() {
givenTasksABCDEF();
whenTriggerMove(F, null);
@ -52,7 +63,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(F, 5, 0);
}
public void disabled_testMoveDownToListBottom() {
@Ignore
@Test
public void testMoveDownToListBottom() {
givenTasksABCDEF();
whenTriggerMove(E, null);
@ -61,7 +74,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(F, 4, 0);
}
public void disabled_testMoveUpSimple() {
@Ignore
@Test
public void testMoveUpSimple() {
givenTasksABCDEF();
whenTriggerMove(F, E);
@ -70,7 +85,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(F, 4, 0);
}
public void disabled_testMoveUpWithSubtasks() {
@Ignore
@Test
public void testMoveUpWithSubtasks() {
givenTasksABCDEF();
whenTriggerMove(C, B);
@ -88,7 +105,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(D, 2, 2);
}
public void disabled_testMoveDownThroughSubtasks() {
@Ignore
@Test
public void testMoveDownThroughSubtasks() {
givenTasksABCDEF();
whenTriggerMove(B, E);
@ -107,7 +126,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(D, 2, 2);
}
public void disabled_testMoveUpAboveParent() {
@Ignore
@Test
public void testMoveUpAboveParent() {
givenTasksABCDEF();
whenTriggerMove(B, A);
@ -126,7 +147,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(C, 2, 1);
}
public void disabled_testMoveDownWithChildren() {
@Ignore
@Test
public void testMoveDownWithChildren() {
givenTasksABCDEF();
whenTriggerMove(C, F);
@ -147,7 +170,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(E, 2, 0);
}
public void disabled_testMoveDownIndentingTwice() {
@Ignore
@Test
public void testMoveDownIndentingTwice() {
givenTasksABCDEF();
whenTriggerMove(D, F);
@ -167,7 +192,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(E, 3, 0);
}
public void disabled_testMoveUpMultiple() {
@Ignore
@Test
public void testMoveUpMultiple() {
givenTasksABCDEF();
whenTriggerMove(C, A);
@ -185,7 +212,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(D, 1, 1);
}
public void disabled_testMoveUpIntoSublist() {
@Ignore
@Test
public void testMoveUpIntoSublist() {
givenTasksABCDEF();
whenTriggerMove(F, D);
@ -206,7 +235,9 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
thenExpectMetadataOrderAndIndent(F, 3, 2);
}
public void disabled_testMoveDownMultiple() {
@Ignore
@Test
public void testMoveDownMultiple() {
givenTasksABCDEF();
whenTriggerMove(B, F);
@ -243,7 +274,7 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
}
@Override
protected void setUp() {
public void setUp() {
super.setUp();
List<TaskList> items = new ArrayList<>();
@ -291,5 +322,4 @@ public class GtasksTaskMovingTest extends DatabaseTestCase {
metadataDao.persist(metadata);
return task;
}
}

@ -1,7 +1,12 @@
package com.todoroo.astrid.gtasks.api;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.time.DateTime;
import java.util.Date;
@ -12,35 +17,41 @@ import static com.todoroo.astrid.gtasks.api.GtasksApiUtilities.gtasksCompletedTi
import static com.todoroo.astrid.gtasks.api.GtasksApiUtilities.gtasksDueTimeToUnixTime;
import static com.todoroo.astrid.gtasks.api.GtasksApiUtilities.unixTimeToGtasksCompletionTime;
import static com.todoroo.astrid.gtasks.api.GtasksApiUtilities.unixTimeToGtasksDueDate;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
public class GtasksApiUtilitiesTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class GtasksApiUtilitiesTest {
private static final Locale defaultLocale = Locale.getDefault();
private static final TimeZone defaultDateTimeZone = TimeZone.getDefault();
@Override
@Before
public void setUp() {
Locale.setDefault(Locale.US);
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago"));
}
@Override
@After
public void tearDown() {
Locale.setDefault(defaultLocale);
TimeZone.setDefault(defaultDateTimeZone);
}
@Test
public void testConvertUnixToGoogleCompletionTime() {
long now = new DateTime(2014, 1, 8, 8, 53, 20, 109).getMillis();
assertEquals(now, unixTimeToGtasksCompletionTime(now).getValue());
}
@Test
public void testConvertGoogleCompletedTimeToUnixTime() {
long now = new DateTime(2014, 1, 8, 8, 53, 20, 109).getMillis();
com.google.api.client.util.DateTime gtime = new com.google.api.client.util.DateTime(now);
assertEquals(now, gtasksCompletedTimeToUnixTime(gtime));
}
@Test
public void testConvertDueDateTimeToGoogleDueDate() {
DateTime now = new DateTime(2014, 1, 8, 8, 53, 20, 109);
@ -49,7 +60,9 @@ public class GtasksApiUtilitiesTest extends AndroidTestCase {
unixTimeToGtasksDueDate(now.getMillis()).getValue());
}
public void disabled_testConvertGoogleDueDateToUnixTime() {
@Ignore
@Test
public void testConvertGoogleDueDateToUnixTime() {
com.google.api.client.util.DateTime googleDueDate =
new com.google.api.client.util.DateTime(
new Date(new DateTime(2014, 1, 8, 0, 0, 0, 0).getMillis()), TimeZone.getTimeZone("GMT"));
@ -59,11 +72,13 @@ public class GtasksApiUtilitiesTest extends AndroidTestCase {
gtasksDueTimeToUnixTime(googleDueDate));
}
@Test
public void testConvertToInvalidGtaskTimes() {
assertNull(unixTimeToGtasksCompletionTime(-1));
assertNull(unixTimeToGtasksDueDate(-1));
}
@Test
public void testConvertFromInvalidGtaskTimes() {
assertEquals(0, gtasksCompletedTimeToUnixTime(null));
assertEquals(0, gtasksDueTimeToUnixTime(null));

@ -1,22 +1,27 @@
package org.tasks.gtasks;
import android.test.AndroidTestCase;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.astrid.data.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.time.DateTime;
import static com.natpryce.makeiteasy.MakeItEasy.with;
import static com.todoroo.astrid.data.Task.HIDE_UNTIL_DUE;
import static com.todoroo.astrid.data.Task.HIDE_UNTIL_DUE_TIME;
import static junit.framework.Assert.assertEquals;
import static org.tasks.gtasks.GoogleTaskSyncAdapter.mergeDates;
import static org.tasks.makers.TaskMaker.DUE_DATE;
import static org.tasks.makers.TaskMaker.DUE_TIME;
import static org.tasks.makers.TaskMaker.HIDE_TYPE;
import static org.tasks.makers.TaskMaker.newTask;
public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class GoogleTaskSyncAdapterTest {
@Test
public void testMergeDate() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)));
@ -26,6 +31,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(new DateTime(2016, 3, 11, 12, 0).getMillis(), remote.getDueDate().longValue());
}
@Test
public void testMergeTime() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 11, 13, 30)));
@ -37,6 +43,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
remote.getDueDate().longValue());
}
@Test
public void testDueDateAdjustHideBackwards() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
@ -46,6 +53,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(new DateTime(2016, 3, 11).getMillis(), remote.getHideUntil().longValue());
}
@Test
public void testDueDateAdjustHideForwards() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 14)));
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
@ -55,6 +63,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(new DateTime(2016, 3, 14).getMillis(), remote.getHideUntil().longValue());
}
@Test
public void testDueTimeAdjustHideBackwards() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 11)));
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),
@ -65,6 +74,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(new DateTime(2016, 3, 11, 13, 30, 1).getMillis(), remote.getHideUntil().longValue());
}
@Test
public void testDueTimeAdjustTimeForwards() {
Task remote = newTask(with(DUE_DATE, new DateTime(2016, 3, 14)));
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),
@ -75,6 +85,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(new DateTime(2016, 3, 14, 13, 30, 1).getMillis(), remote.getHideUntil().longValue());
}
@Test
public void testDueDateClearHide() {
Task remote = newTask();
Task local = newTask(with(DUE_DATE, new DateTime(2016, 3, 12)), with(HIDE_TYPE, HIDE_UNTIL_DUE));
@ -84,6 +95,7 @@ public class GoogleTaskSyncAdapterTest extends AndroidTestCase {
assertEquals(0, remote.getHideUntil().longValue());
}
@Test
public void testDueTimeClearHide() {
Task remote = newTask();
Task local = newTask(with(DUE_TIME, new DateTime(2016, 3, 12, 13, 30)),

Loading…
Cancel
Save