mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Make all unit tests inherit from BaseTest
This commit is contained in:
@@ -23,7 +23,9 @@ import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -34,6 +36,9 @@ public class BaseTest
|
||||
protected Context targetContext;
|
||||
private static boolean isLooperPrepared;
|
||||
|
||||
public static final long FIXED_LOCAL_TIME = 1422172800000L; // 8:00am, January 25th, 2015 (UTC)
|
||||
|
||||
@Before
|
||||
protected void setup()
|
||||
{
|
||||
if(!isLooperPrepared)
|
||||
@@ -44,6 +49,8 @@ public class BaseTest
|
||||
|
||||
targetContext = InstrumentationRegistry.getTargetContext();
|
||||
testContext = InstrumentationRegistry.getContext();
|
||||
|
||||
DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
}
|
||||
|
||||
protected void waitForAsyncTasks() throws InterruptedException, TimeoutException
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.isoron.uhabits.models.Habit;
|
||||
|
||||
public class HabitFixtures
|
||||
{
|
||||
public static final long FIXED_LOCAL_TIME = 1422172800000L; // 8:00am, January 25th, 2015 (UTC)
|
||||
public static boolean NON_DAILY_HABIT_CHECKS[] = { true, false, false, true, true, true, false,
|
||||
false, true, true };
|
||||
|
||||
@@ -85,14 +84,4 @@ public class HabitFixtures
|
||||
for(Habit h : Habit.getAll(true))
|
||||
h.cascadeDelete();
|
||||
}
|
||||
|
||||
public static void fixTime()
|
||||
{
|
||||
DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
}
|
||||
|
||||
public static void releaseTime()
|
||||
{
|
||||
DateHelper.setFixedLocalTime(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DatabaseHelper;
|
||||
import org.isoron.uhabits.io.HabitsCSVExporter;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
@@ -44,13 +45,15 @@ import static junit.framework.Assert.assertTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class HabitsCSVExporterTest
|
||||
public class HabitsCSVExporterTest extends BaseTest
|
||||
{
|
||||
private File baseDir;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
HabitFixtures.createNonDailyHabit();
|
||||
HabitFixtures.createEmptyHabit();
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DatabaseHelper;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.io.GenericImporter;
|
||||
@@ -48,7 +49,7 @@ import static org.junit.Assert.fail;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ImportTest
|
||||
public class ImportTest extends BaseTest
|
||||
{
|
||||
private File baseDir;
|
||||
private Context context;
|
||||
@@ -56,6 +57,9 @@ public class ImportTest
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
DateHelper.setFixedLocalTime(null);
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
context = InstrumentationRegistry.getInstrumentation().getContext();
|
||||
baseDir = DatabaseHelper.getFilesDir("Backups");
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.unit.models;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.unit.HabitFixtures;
|
||||
@@ -41,16 +42,17 @@ import static org.isoron.uhabits.models.Checkmark.UNCHECKED;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class CheckmarkListTest
|
||||
public class CheckmarkListTest extends BaseTest
|
||||
{
|
||||
Habit nonDailyHabit;
|
||||
private Habit emptyHabit;
|
||||
|
||||
@Before
|
||||
public void prepare()
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
DateHelper.setFixedLocalTime(HabitFixtures.FIXED_LOCAL_TIME);
|
||||
nonDailyHabit = HabitFixtures.createNonDailyHabit();
|
||||
emptyHabit = HabitFixtures.createEmptyHabit();
|
||||
}
|
||||
@@ -167,7 +169,7 @@ public class CheckmarkListTest
|
||||
|
||||
private void travelInTime(int days)
|
||||
{
|
||||
DateHelper.setFixedLocalTime(HabitFixtures.FIXED_LOCAL_TIME +
|
||||
DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME +
|
||||
days * DateHelper.millisecondsInOneDay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.unit.HabitFixtures;
|
||||
@@ -45,11 +46,12 @@ import static org.junit.Assert.fail;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class HabitTest
|
||||
public class HabitTest extends BaseTest
|
||||
{
|
||||
@Before
|
||||
public void prepare()
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
HabitFixtures.purgeHabits();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.unit.models;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.unit.HabitFixtures;
|
||||
@@ -41,16 +42,17 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class RepetitionListTest
|
||||
public class RepetitionListTest extends BaseTest
|
||||
{
|
||||
Habit habit;
|
||||
private Habit habit;
|
||||
private Habit emptyHabit;
|
||||
|
||||
@Before
|
||||
public void prepare()
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
DateHelper.setFixedLocalTime(HabitFixtures.FIXED_LOCAL_TIME);
|
||||
habit = HabitFixtures.createNonDailyHabit();
|
||||
emptyHabit = HabitFixtures.createEmptyHabit();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.unit.models;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.helpers.DatabaseHelper;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
@@ -40,15 +41,16 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ScoreListTest
|
||||
public class ScoreListTest extends BaseTest
|
||||
{
|
||||
private Habit habit;
|
||||
|
||||
@Before
|
||||
public void prepare()
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
DateHelper.setFixedLocalTime(HabitFixtures.FIXED_LOCAL_TIME);
|
||||
habit = HabitFixtures.createEmptyHabit();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,10 @@ package org.isoron.uhabits.unit.models;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.BaseTest;
|
||||
import org.isoron.uhabits.models.Checkmark;
|
||||
import org.isoron.uhabits.models.Score;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -32,8 +34,14 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ScoreTest
|
||||
public class ScoreTest extends BaseTest
|
||||
{
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compute_withDailyHabit()
|
||||
{
|
||||
|
||||
@@ -46,8 +46,6 @@ public class HabitHistoryViewTest extends ViewTest
|
||||
super.setup();
|
||||
|
||||
HabitFixtures.purgeHabits();
|
||||
HabitFixtures.fixTime();
|
||||
|
||||
habit = HabitFixtures.createLongHabit();
|
||||
|
||||
view = new HabitHistoryView(targetContext);
|
||||
|
||||
Reference in New Issue
Block a user