urbanairship-core/src/test/java/com/urbanairship/analytics/data/EventManagerTest.java
@Test
    public void testSendEventsFails() {
        Map<String, String> events = new HashMap<>();
        events.put("firstEvent", "{ 'firstEventBody' }");
        when(mockEventResolver.getEventCount()).thenReturn(1);
        when(mockEventResolver.getDatabaseSize()).thenReturn(100);
        when(mockEventResolver.getEvents(1)).thenReturn(events);

        dataStore.put(EventManager.MAX_BATCH_SIZE_KEY, 100);


        // Start the upload process
        when(mockClient.sendEvents(UAirship.shared(), events.values())).thenReturn(null);

        assertFalse(eventManager.uploadEvents(UAirship.shared()));

        // Check mockClient receives the events
        verify(mockClient).sendEvents(UAirship.shared(), events.values());

        // If it fails, it should skip deleting events
        verify(mockEventResolver, never()).deleteEvents(events.keySet());
    }
/**
     * Test sending events when the upload fails.
     */
Test sending events when the upload fails.
Test sending events when the upload fails .
@Test
    public void testSendEventsFails() {
        Map<String, String> events = new HashMap<>();
        events.put("firstEvent", "{ 'firstEventBody' }");
        when(mockEventResolver.getEventCount()).thenReturn(1);
        when(mockEventResolver.getDatabaseSize()).thenReturn(100);
        when(mockEventResolver.getEvents(1)).thenReturn(events);
        dataStore.put(EventManager.MAX_BATCH_SIZE_KEY, 100);
        when(mockClient.sendEvents(UAirship.shared(), events.values())).thenReturn(null);
        assertFalse(eventManager.uploadEvents(UAirship.shared()));
        verify(mockClient).sendEvents(UAirship.shared(), events.values());
        verify(mockEventResolver, never()).deleteEvents(events.keySet());
    }
@ Test public void testSendEventsFails ( ) { Map < String , String > events = new HashMap < > ( ) ; events . put ( "firstEvent" , "{ 'firstEventBody' }" ) ; when ( mockEventResolver . getEventCount ( ) ) . thenReturn ( 1 ) ; when ( mockEventResolver . getDatabaseSize ( ) ) . thenReturn ( 100 ) ; when ( mockEventResolver . getEvents ( 1 ) ) . thenReturn ( events ) ; dataStore . put ( EventManager . MAX_BATCH_SIZE_KEY , 100 ) ; when ( mockClient . sendEvents ( UAirship . shared ( ) , events . values ( ) ) ) . thenReturn ( null ) ; assertFalse ( eventManager . uploadEvents ( UAirship . shared ( ) ) ) ; verify ( mockClient ) . sendEvents ( UAirship . shared ( ) , events . values ( ) ) ; verify ( mockEventResolver , never ( ) ) . deleteEvents ( events . keySet ( ) ) ; }
Test sending events when the upload fails.
Test sending events when the upload fails .
// Start the upload process // Check mockClient receives the events // If it fails, it should skip deleting events