4343import com .onesignal .NotificationExtenderService ;
4444import com .onesignal .NotificationOpenedProcessor ;
4545import com .onesignal .OSNotificationPayload ;
46- import com .onesignal .OneSignal ;
4746import com .onesignal .OneSignalDbHelper ;
4847import com .onesignal .OneSignalPackagePrivateHelper ;
4948import com .onesignal .ShadowBadgeCountUpdater ;
7069import org .robolectric .util .ServiceController ;
7170
7271import java .util .Iterator ;
73- import java .util .List ;
7472import java .util .Map ;
7573
74+ import static com .onesignal .OneSignalPackagePrivateHelper .NotificationBundleProcessor_ProcessFromGCMIntentService ;
75+ import static com .onesignal .OneSignalPackagePrivateHelper .NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap ;
76+ import static com .onesignal .OneSignalPackagePrivateHelper .createInternalPayloadBundle ;
77+
7678@ Config (packageName = "com.onesignal.example" ,
7779 constants = BuildConfig .class ,
7880 shadows = { ShadowRoboNotificationManager .class , ShadowOneSignalRestClient .class , ShadowBadgeCountUpdater .class },
@@ -129,23 +131,33 @@ private Intent createOpenIntent(Bundle bundle) {
129131 public void shouldSetTitleCorrectly () throws Exception {
130132 // Should use app's Title by default
131133 Bundle bundle = getBaseNotifBundle ();
132- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
134+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
133135 Assert .assertEquals ("UnitTestApp" , ShadowRoboNotificationManager .lastNotif .getContentTitle ());
134136 Assert .assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
135137
136138 // Should allow title from GCM payload.
137139 bundle = getBaseNotifBundle ("UUID2" );
138140 bundle .putString ("title" , "title123" );
139- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
141+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
140142 Assert .assertEquals ("title123" , ShadowRoboNotificationManager .lastNotif .getContentTitle ());
141143 Assert .assertEquals (2 , ShadowBadgeCountUpdater .lastCount );
142144 }
143145
146+ @ Test
147+ public void shouldProcessRestore () throws Exception {
148+ Bundle bundle = createInternalPayloadBundle (getBaseNotifBundle ());
149+ bundle .putInt ("android_notif_id" , 0 );
150+ bundle .putBoolean ("restoring" , true );
151+
152+ NotificationBundleProcessor_ProcessFromGCMIntentService_NoWrap (blankActivity , bundle , null );
153+ Assert .assertEquals ("UnitTestApp" , ShadowRoboNotificationManager .lastNotif .getContentTitle ());
154+ }
155+
144156 @ Test
145157 public void shouldHandleBasicNotifications () throws Exception {
146158 // Make sure the notification got posted and the content is correct.
147159 Bundle bundle = getBaseNotifBundle ();
148- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
160+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
149161 Assert .assertEquals (notifMessage , ShadowRoboNotificationManager .lastNotif .getContentText ());
150162 Assert .assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
151163
@@ -167,14 +179,14 @@ public void shouldHandleBasicNotifications() throws Exception {
167179 int firstNotifId = cursor .getInt (1 );
168180
169181 // Should not display a duplicate notification, count should still be 1
170- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
182+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
171183 cursor = readableDb .query (NotificationTable .TABLE_NAME , null , null , null , null , null , null );
172184 Assert .assertEquals (1 , cursor .getCount ());
173185 Assert .assertEquals (0 , ShadowBadgeCountUpdater .lastCount );
174186
175187 // Display a second notification
176188 bundle = getBaseNotifBundle ("UUID2" );
177- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
189+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
178190 cursor = readableDb .query (NotificationTable .TABLE_NAME , new String [] { "android_notification_id" }, "android_notification_id <> " + firstNotifId , null , null , null , null );
179191 cursor .moveToFirst ();
180192 int secondNotifId = cursor .getInt (0 );
@@ -186,7 +198,7 @@ public void shouldHandleBasicNotifications() throws Exception {
186198 // Should of been added for a total of 2 records now.
187199 // First opened should of been cleaned up, 1 week old non opened notification should stay, and one new record.
188200 bundle = getBaseNotifBundle ("UUID3" );
189- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
201+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
190202 cursor = readableDb .query (NotificationTable .TABLE_NAME , new String [] { "android_notification_id" }, null , null , null , null , null );
191203 Assert .assertEquals (2 , cursor .getCount ());
192204 Assert .assertEquals (2 , ShadowBadgeCountUpdater .lastCount );
@@ -208,7 +220,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
208220 // Make sure the notification got posted and the content is correct.
209221 Bundle bundle = getBaseNotifBundle ();
210222 bundle .putString ("grp" , "test1" );
211- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
223+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
212224
213225 Map <Integer , PostedNotification > postedNotifs = ShadowRoboNotificationManager .notifications ;
214226 Assert .assertEquals (2 , postedNotifs .size ());
@@ -240,7 +252,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
240252 bundle .putString ("alert" , "Notif test 2" );
241253 bundle .putString ("custom" , "{\" i\" : \" UUID2\" }" );
242254 bundle .putString ("grp" , "test1" );
243- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
255+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
244256
245257 postedNotifs = ShadowRoboNotificationManager .notifications ;
246258 Assert .assertEquals (2 , postedNotifs .size ());
@@ -275,7 +287,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
275287 bundle .putString ("alert" , "Notif test 3" );
276288 bundle .putString ("custom" , "{\" i\" : \" UUID3\" }" );
277289 bundle .putString ("grp" , "test1" );
278- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
290+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
279291
280292 postedNotifsIterator = postedNotifs .entrySet ().iterator ();
281293 postedNotification = postedNotifsIterator .next ().getValue ();
@@ -336,7 +348,7 @@ public void shouldFireNotificationExtenderService() throws Exception {
336348 ServiceController <NotificationExtenderServiceTest > controller = Robolectric .buildService (NotificationExtenderServiceTest .class );
337349 NotificationExtenderServiceTest service = controller .attach ().create ().get ();
338350 Intent testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
339- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBundleWithAllOptionsSet ()));
351+ testIntent .putExtras (createInternalPayloadBundle (getBundleWithAllOptionsSet ()));
340352 controller .withIntent (testIntent ).startCommand (0 , 0 );
341353
342354 OSNotificationPayload notification = service .notification ;
@@ -372,15 +384,15 @@ public void shouldFireNotificationExtenderService() throws Exception {
372384
373385 // Test a basic notification without anything special.
374386 testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
375- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBaseNotifBundle ()));
387+ testIntent .putExtras (createInternalPayloadBundle (getBaseNotifBundle ()));
376388 controller .withIntent (testIntent ).startCommand (0 , 0 );
377389 Assert .assertFalse (ShadowOneSignal .messages .contains ("Error assigning" ));
378390
379391
380392 // Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
381393 NotificationExtenderServiceTest .throwInAppCode = true ;
382394 testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
383- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBaseNotifBundle ("NewUUID1" )));
395+ testIntent .putExtras (createInternalPayloadBundle (getBaseNotifBundle ("NewUUID1" )));
384396 controller .withIntent (testIntent ).startCommand (0 , 0 );
385397
386398 Assert .assertTrue (ShadowOneSignal .messages .contains ("onNotificationProcessing throw an exception" ));
0 commit comments