Snap for 6038280 from cdb69a41fdff54110a5b9ced7aa699e846b77ae5 to rvc-release
Change-Id: I9153af7d393030239be46229d941508a4233f24a
diff --git a/tests/src/com/android/providers/calendar/CalendarSanityCheckerTest.java b/tests/src/com/android/providers/calendar/CalendarSanityCheckerTest.java
index 1586c61..4cd00c8 100644
--- a/tests/src/com/android/providers/calendar/CalendarSanityCheckerTest.java
+++ b/tests/src/com/android/providers/calendar/CalendarSanityCheckerTest.java
@@ -15,11 +15,23 @@
*/
package com.android.providers.calendar;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import android.content.Context;
-import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
import android.text.format.DateUtils;
-public class CalendarSanityCheckerTest extends AndroidTestCase {
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class CalendarSanityCheckerTest {
private class CalendarSanityCheckerTestable extends CalendarSanityChecker {
protected CalendarSanityCheckerTestable(Context context) {
super(context);
@@ -41,73 +53,79 @@
}
}
+ private Context mContext;
+ private CalendarSanityCheckerTestable mSanityChecker;
+
private long mInjectedRealtimeMillis = 1000000L;
private long mInjectedBootCount = 1000;
private long mInjectedUnlockTime = 0;
- public void testWithoutLastCheckTime() {
- CalendarSanityCheckerTestable target = new CalendarSanityCheckerTestable(getContext());
- target.mPrefs.edit().clear().commit();
+ @Before
+ public void setUp() {
+ mContext = InstrumentationRegistry.getContext();
+ mSanityChecker = new CalendarSanityCheckerTestable(mContext);
+ mSanityChecker.mPrefs.edit().clear().commit();
+ }
- assertTrue(target.checkLastCheckTime());
+ @Test
+ public void testWithoutLastCheckTime() {
+ assertTrue(mSanityChecker.checkLastCheckTime());
// Unlock.
mInjectedUnlockTime = mInjectedRealtimeMillis;
mInjectedRealtimeMillis += 15 * 60 * 1000;
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedRealtimeMillis += 1;
- assertFalse(target.checkLastCheckTime());
+ assertFalse(mSanityChecker.checkLastCheckTime());
}
+ @Test
public void testWithLastCheckTime() {
- CalendarSanityCheckerTestable target = new CalendarSanityCheckerTestable(getContext());
- target.mPrefs.edit().clear().commit();
-
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedUnlockTime = mInjectedRealtimeMillis;
// Update the last check time.
mInjectedRealtimeMillis += 1 * 60 * 1000;
- target.updateLastCheckTime();
+ mSanityChecker.updateLastCheckTime();
// Right after, okay.
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
// Still okay.
mInjectedRealtimeMillis += DateUtils.DAY_IN_MILLIS - (15 * DateUtils.MINUTE_IN_MILLIS);
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedRealtimeMillis += 1;
- assertFalse(target.checkLastCheckTime());
+ assertFalse(mSanityChecker.checkLastCheckTime());
// Repeat the same thing.
mInjectedRealtimeMillis += 1 * 60 * 1000;
- target.updateLastCheckTime();
+ mSanityChecker.updateLastCheckTime();
// Right after, okay.
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
// Still okay.
mInjectedRealtimeMillis += DateUtils.DAY_IN_MILLIS - (15 * DateUtils.MINUTE_IN_MILLIS);
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedRealtimeMillis += 1;
- assertFalse(target.checkLastCheckTime());
+ assertFalse(mSanityChecker.checkLastCheckTime());
// Check again right after. This should pass because of WTF_INTERVAL_MS.
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedRealtimeMillis += 60 * 60 * 1000;
// Still okay.
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
// Now WTF again.
mInjectedRealtimeMillis += 1;
- assertFalse(target.checkLastCheckTime());
+ assertFalse(mSanityChecker.checkLastCheckTime());
// Reboot.
mInjectedRealtimeMillis = 1000000L;
@@ -117,12 +135,12 @@
mInjectedUnlockTime = mInjectedRealtimeMillis;
mInjectedRealtimeMillis += 15 * 60 * 1000;
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
mInjectedRealtimeMillis += 1;
- assertFalse(target.checkLastCheckTime());
+ assertFalse(mSanityChecker.checkLastCheckTime());
// Check again right after. This should pass because of WTF_INTERVAL_MS.
- assertTrue(target.checkLastCheckTime());
+ assertTrue(mSanityChecker.checkLastCheckTime());
}
}