urbanairship-core/src/test/java/com/urbanairship/push/IncomingPushRunnableTest.java
@Test
    public void testNotificationFactoryException() {
        when(pushManager.isComponentEnabled()).thenReturn(true);
        when(pushManager.isPushEnabled()).thenReturn(true);
        when(pushManager.isOptIn()).thenReturn(true);
        when(pushManager.isUniqueCanonicalId("testPushID")).thenReturn(true);

        // Set a notification factory that throws an exception
        notificationFactory = new NotificationFactory(TestApplication.getApplication()) {
            @Override
            public Notification createNotification(@NonNull PushMessage pushMessage, int notificationId) {
                throw new RuntimeException("Unable to create and display notification.");
            }

            @Override
            public int getNextId(@NonNull PushMessage pushMessage) {
                return 0;
            }
        };

        pushRunnable.run();

        verify(notificationManager, Mockito.never()).notify(Mockito.anyString(), Mockito.anyInt(), any(Notification.class));
        verify(jobDispatcher, Mockito.never()).dispatch(any(JobInfo.class));
    }
/**
     * Test handling an exceptions from the notification factory.
     */
Test handling an exceptions from the notification factory.
Test handling an exceptions from the notification factory .
@Test
    public void testNotificationFactoryException() {
        when(pushManager.isComponentEnabled()).thenReturn(true);
        when(pushManager.isPushEnabled()).thenReturn(true);
        when(pushManager.isOptIn()).thenReturn(true);
        when(pushManager.isUniqueCanonicalId("testPushID")).thenReturn(true);
        notificationFactory = new NotificationFactory(TestApplication.getApplication()) {
            @Override
            public Notification createNotification(@NonNull PushMessage pushMessage, int notificationId) {
                throw new RuntimeException("Unable to create and display notification.");
            }
            @Override
            public int getNextId(@NonNull PushMessage pushMessage) {
                return 0;
            }
        };
        pushRunnable.run();
        verify(notificationManager, Mockito.never()).notify(Mockito.anyString(), Mockito.anyInt(), any(Notification.class));
        verify(jobDispatcher, Mockito.never()).dispatch(any(JobInfo.class));
    }
@ Test public void testNotificationFactoryException ( ) { when ( pushManager . isComponentEnabled ( ) ) . thenReturn ( true ) ; when ( pushManager . isPushEnabled ( ) ) . thenReturn ( true ) ; when ( pushManager . isOptIn ( ) ) . thenReturn ( true ) ; when ( pushManager . isUniqueCanonicalId ( "testPushID" ) ) . thenReturn ( true ) ; notificationFactory = new NotificationFactory ( TestApplication . getApplication ( ) ) { @ Override public Notification createNotification ( @ NonNull PushMessage pushMessage , int notificationId ) { throw new RuntimeException ( "Unable to create and display notification." ) ; } @ Override public int getNextId ( @ NonNull PushMessage pushMessage ) { return 0 ; } } ; pushRunnable . run ( ) ; verify ( notificationManager , Mockito . never ( ) ) . notify ( Mockito . anyString ( ) , Mockito . anyInt ( ) , any ( Notification . class ) ) ; verify ( jobDispatcher , Mockito . never ( ) ) . dispatch ( any ( JobInfo . class ) ) ; }
Test handling an exceptions from the notification factory.
Test handling an exceptions from the notification factory .
// Set a notification factory that throws an exception