@@ -1983,6 +1983,64 @@ public void remoteNotificationReceived(Context context, OSNotificationReceivedEv
1983
1983
}
1984
1984
}
1985
1985
1986
+ @ Test
1987
+ @ Config (shadows = { ShadowGenerateNotification .class })
1988
+ public void testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays () throws Exception {
1989
+ // 1. Setup correct notification extension service class
1990
+ startRemoteNotificationReceivedHandlerService (
1991
+ RemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification
1992
+ .class
1993
+ .getName ()
1994
+ );
1995
+
1996
+ // 2. Init OneSignal
1997
+ OneSignal .setAppId ("b2f7f966-d8cc-11e4-bed1-df8f05be55ba" );
1998
+ OneSignal .initWithContext (blankActivity );
1999
+ OneSignal .setNotificationWillShowInForegroundHandler (notificationReceivedEvent -> {
2000
+ lastForegroundNotificationReceivedEvent = notificationReceivedEvent ;
2001
+
2002
+ // Call complete to end without waiting default 30 second timeout
2003
+ notificationReceivedEvent .complete (notificationReceivedEvent .getNotification ());
2004
+ });
2005
+ threadAndTaskWait ();
2006
+
2007
+ blankActivityController .resume ();
2008
+ threadAndTaskWait ();
2009
+
2010
+ // 3. Receive a notification in foreground
2011
+ FCMBroadcastReceiver_processBundle (blankActivity , getBaseNotifBundle ());
2012
+ threadAndTaskWait ();
2013
+
2014
+ // 4. Make sure service was called
2015
+ assertNotNull (lastServiceNotificationReceivedEvent );
2016
+
2017
+ // 5. Make sure foreground handler was called
2018
+ assertNotNull (lastForegroundNotificationReceivedEvent );
2019
+
2020
+ // 6. Make sure running on main thread check is called, this is only called for showing the notification
2021
+ assertTrue (ShadowGenerateNotification .isRunningOnMainThreadCheckCalled ());
2022
+
2023
+ // 7. Check badge count to represent the notification is displayed
2024
+ assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
2025
+ }
2026
+
2027
+ /**
2028
+ * @see #testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays
2029
+ */
2030
+ public static class RemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification implements OneSignal .OSRemoteNotificationReceivedHandler {
2031
+
2032
+ @ Override
2033
+ public void remoteNotificationReceived (final Context context , OSNotificationReceivedEvent receivedEvent ) {
2034
+ lastServiceNotificationReceivedEvent = receivedEvent ;
2035
+
2036
+ OSNotification notification = receivedEvent .getNotification ();
2037
+ OSMutableNotification mutableNotification = notification .mutableCopy ();
2038
+
2039
+ // Complete is called to end NotificationProcessingHandler
2040
+ receivedEvent .complete (mutableNotification );
2041
+ }
2042
+ }
2043
+
1986
2044
@ Test
1987
2045
@ Config (shadows = { ShadowGenerateNotification .class })
1988
2046
public void testNotificationWillShowInForegroundHandlerIsCallWhenReceivingNotificationInForeground () throws Exception {
0 commit comments