106
106
import static com .onesignal .OneSignalPackagePrivateHelper .NotificationOpenedProcessor_processFromContext ;
107
107
import static com .onesignal .OneSignalPackagePrivateHelper .NotificationSummaryManager_updateSummaryNotificationAfterChildRemoved ;
108
108
import static com .onesignal .OneSignalPackagePrivateHelper .createInternalPayloadBundle ;
109
- import static com .test .onesignal .TestHelpers .advanceTimeByMs ;
109
+ import static com .test .onesignal .TestHelpers .advanceSystemTimeBy ;
110
110
import static com .test .onesignal .TestHelpers .threadAndTaskWait ;
111
111
import static junit .framework .Assert .assertEquals ;
112
112
import static junit .framework .Assert .assertFalse ;
@@ -147,9 +147,6 @@ public static void setUpClass() throws Exception {
147
147
148
148
@ Before // Before each test
149
149
public void beforeEachTest () throws Exception {
150
- // Robolectric mocks System.currentTimeMillis() to 0, we need the current real time to match our SQL records.
151
- SystemClock .setCurrentTimeMillis (System .currentTimeMillis ());
152
-
153
150
blankActivityController = Robolectric .buildActivity (BlankActivity .class ).create ();
154
151
blankActivity = blankActivityController .get ();
155
152
blankActivity .getApplicationInfo ().name = "UnitTestApp" ;
@@ -164,7 +161,7 @@ public void beforeEachTest() throws Exception {
164
161
notificationManager .cancelAll ();
165
162
NotificationRestorer .restored = false ;
166
163
}
167
-
164
+
168
165
@ AfterClass
169
166
public static void afterEverything () throws Exception {
170
167
StaticResetHelper .restSetStaticFields ();
@@ -259,7 +256,7 @@ public void notificationOpened(OSNotificationOpenResult result) {
259
256
NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
260
257
261
258
// Go forward 4 weeks
262
- SystemClock . setCurrentTimeMillis ( System . currentTimeMillis () + 2419202L * 1000L );
259
+ advanceSystemTimeBy ( 2_419_202 );
263
260
264
261
// Display a 3 normal notification.
265
262
NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , getBaseNotifBundle ("UUID3" ), null );
@@ -805,7 +802,7 @@ public void shouldHandleBasicNotifications() {
805
802
806
803
// Go forward 4 weeks
807
804
// Note: Does not effect the SQL function strftime
808
- SystemClock . setCurrentTimeMillis ( System . currentTimeMillis () + 2419201L * 1000L );
805
+ advanceSystemTimeBy ( 2_419_202 );
809
806
810
807
// Display a 3rd notification
811
808
// Should of been added for a total of 2 records now.
@@ -832,7 +829,7 @@ public void shouldRestoreNotifications() {
832
829
833
830
// Go forward 1 week
834
831
// Note: Does not effect the SQL function strftime
835
- SystemClock . setCurrentTimeMillis ( System . currentTimeMillis () + 604801L * 1000L );
832
+ advanceSystemTimeBy ( 604_801 );
836
833
837
834
// Restorer should not fire service since the notification is over 1 week old.
838
835
NotificationRestorer .restore (blankActivity ); NotificationRestorer .restored = false ;
@@ -863,7 +860,7 @@ private void helperShouldRestoreNotificationsPastExpireTime(boolean should) {
863
860
assertRestoreRan ();
864
861
865
862
// Go forward just past the TTL of the notification
866
- advanceTimeByMs (( ttl + 1 ) * 1_000L );
863
+ advanceSystemTimeBy ( ttl + 1 );
867
864
restoreNotifications ();
868
865
if (should )
869
866
assertRestoreRan ();
@@ -887,7 +884,7 @@ public void badgeCountShouldNotIncludeOldNotifications() {
887
884
NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , getBaseNotifBundle (), null );
888
885
889
886
// Go forward 1 week
890
- SystemClock . setCurrentTimeMillis ( System . currentTimeMillis () + 604801 * 1000 );
887
+ advanceSystemTimeBy ( 604_801 );
891
888
892
889
// Should not count as a badge
893
890
SQLiteDatabase readableDb = OneSignalDbHelper .getInstance (blankActivity ).getReadableDatabase ();
0 commit comments