43
43
import com .onesignal .NotificationExtenderService ;
44
44
import com .onesignal .NotificationOpenedProcessor ;
45
45
import com .onesignal .OSNotificationPayload ;
46
- import com .onesignal .OneSignal ;
47
46
import com .onesignal .OneSignalDbHelper ;
48
47
import com .onesignal .OneSignalPackagePrivateHelper ;
49
48
import com .onesignal .ShadowBadgeCountUpdater ;
70
69
import org .robolectric .util .ServiceController ;
71
70
72
71
import java .util .Iterator ;
73
- import java .util .List ;
74
72
import java .util .Map ;
75
73
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
+
76
78
@ Config (packageName = "com.onesignal.example" ,
77
79
constants = BuildConfig .class ,
78
80
shadows = { ShadowRoboNotificationManager .class , ShadowOneSignalRestClient .class , ShadowBadgeCountUpdater .class },
@@ -129,23 +131,33 @@ private Intent createOpenIntent(Bundle bundle) {
129
131
public void shouldSetTitleCorrectly () throws Exception {
130
132
// Should use app's Title by default
131
133
Bundle bundle = getBaseNotifBundle ();
132
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
134
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
133
135
Assert .assertEquals ("UnitTestApp" , ShadowRoboNotificationManager .lastNotif .getContentTitle ());
134
136
Assert .assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
135
137
136
138
// Should allow title from GCM payload.
137
139
bundle = getBaseNotifBundle ("UUID2" );
138
140
bundle .putString ("title" , "title123" );
139
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
141
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
140
142
Assert .assertEquals ("title123" , ShadowRoboNotificationManager .lastNotif .getContentTitle ());
141
143
Assert .assertEquals (2 , ShadowBadgeCountUpdater .lastCount );
142
144
}
143
145
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
+
144
156
@ Test
145
157
public void shouldHandleBasicNotifications () throws Exception {
146
158
// Make sure the notification got posted and the content is correct.
147
159
Bundle bundle = getBaseNotifBundle ();
148
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
160
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
149
161
Assert .assertEquals (notifMessage , ShadowRoboNotificationManager .lastNotif .getContentText ());
150
162
Assert .assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
151
163
@@ -167,14 +179,14 @@ public void shouldHandleBasicNotifications() throws Exception {
167
179
int firstNotifId = cursor .getInt (1 );
168
180
169
181
// Should not display a duplicate notification, count should still be 1
170
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
182
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
171
183
cursor = readableDb .query (NotificationTable .TABLE_NAME , null , null , null , null , null , null );
172
184
Assert .assertEquals (1 , cursor .getCount ());
173
185
Assert .assertEquals (0 , ShadowBadgeCountUpdater .lastCount );
174
186
175
187
// Display a second notification
176
188
bundle = getBaseNotifBundle ("UUID2" );
177
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
189
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
178
190
cursor = readableDb .query (NotificationTable .TABLE_NAME , new String [] { "android_notification_id" }, "android_notification_id <> " + firstNotifId , null , null , null , null );
179
191
cursor .moveToFirst ();
180
192
int secondNotifId = cursor .getInt (0 );
@@ -186,7 +198,7 @@ public void shouldHandleBasicNotifications() throws Exception {
186
198
// Should of been added for a total of 2 records now.
187
199
// First opened should of been cleaned up, 1 week old non opened notification should stay, and one new record.
188
200
bundle = getBaseNotifBundle ("UUID3" );
189
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
201
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
190
202
cursor = readableDb .query (NotificationTable .TABLE_NAME , new String [] { "android_notification_id" }, null , null , null , null , null );
191
203
Assert .assertEquals (2 , cursor .getCount ());
192
204
Assert .assertEquals (2 , ShadowBadgeCountUpdater .lastCount );
@@ -208,7 +220,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
208
220
// Make sure the notification got posted and the content is correct.
209
221
Bundle bundle = getBaseNotifBundle ();
210
222
bundle .putString ("grp" , "test1" );
211
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
223
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
212
224
213
225
Map <Integer , PostedNotification > postedNotifs = ShadowRoboNotificationManager .notifications ;
214
226
Assert .assertEquals (2 , postedNotifs .size ());
@@ -240,7 +252,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
240
252
bundle .putString ("alert" , "Notif test 2" );
241
253
bundle .putString ("custom" , "{\" i\" : \" UUID2\" }" );
242
254
bundle .putString ("grp" , "test1" );
243
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
255
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
244
256
245
257
postedNotifs = ShadowRoboNotificationManager .notifications ;
246
258
Assert .assertEquals (2 , postedNotifs .size ());
@@ -275,7 +287,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
275
287
bundle .putString ("alert" , "Notif test 3" );
276
288
bundle .putString ("custom" , "{\" i\" : \" UUID3\" }" );
277
289
bundle .putString ("grp" , "test1" );
278
- OneSignalPackagePrivateHelper . NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
290
+ NotificationBundleProcessor_ProcessFromGCMIntentService (blankActivity , bundle , null );
279
291
280
292
postedNotifsIterator = postedNotifs .entrySet ().iterator ();
281
293
postedNotification = postedNotifsIterator .next ().getValue ();
@@ -336,7 +348,7 @@ public void shouldFireNotificationExtenderService() throws Exception {
336
348
ServiceController <NotificationExtenderServiceTest > controller = Robolectric .buildService (NotificationExtenderServiceTest .class );
337
349
NotificationExtenderServiceTest service = controller .attach ().create ().get ();
338
350
Intent testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
339
- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBundleWithAllOptionsSet ()));
351
+ testIntent .putExtras (createInternalPayloadBundle (getBundleWithAllOptionsSet ()));
340
352
controller .withIntent (testIntent ).startCommand (0 , 0 );
341
353
342
354
OSNotificationPayload notification = service .notification ;
@@ -372,15 +384,15 @@ public void shouldFireNotificationExtenderService() throws Exception {
372
384
373
385
// Test a basic notification without anything special.
374
386
testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
375
- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBaseNotifBundle ()));
387
+ testIntent .putExtras (createInternalPayloadBundle (getBaseNotifBundle ()));
376
388
controller .withIntent (testIntent ).startCommand (0 , 0 );
377
389
Assert .assertFalse (ShadowOneSignal .messages .contains ("Error assigning" ));
378
390
379
391
380
392
// Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
381
393
NotificationExtenderServiceTest .throwInAppCode = true ;
382
394
testIntent = new Intent (RuntimeEnvironment .application , NotificationExtenderServiceTest .class );
383
- testIntent .putExtras (OneSignalPackagePrivateHelper . createInternalPayloadBundle (getBaseNotifBundle ("NewUUID1" )));
395
+ testIntent .putExtras (createInternalPayloadBundle (getBaseNotifBundle ("NewUUID1" )));
384
396
controller .withIntent (testIntent ).startCommand (0 , 0 );
385
397
386
398
Assert .assertTrue (ShadowOneSignal .messages .contains ("onNotificationProcessing throw an exception" ));
0 commit comments