sample/src/androidTest/java/com/urbanairship/sample/SampleTest.java
@Test
    public void testMessageCenter() throws Exception {
        for (int i = 0; i < 2; i++) {
            RichPushPayload richPushPayload = RichPushPayload.newBuilder()
                                                             .setTitle("message " + i)
                                                             .setHtmlContent("<body id=\"title\">message " + i + "</body>")
                                                             .build();

            PushPayload payload = PushPayload.newChannelPushBuilder(channelId)
                                             .setAlert("message " + i)
                                             .setRichPushMessage(richPushPayload)
                                             .build();
            pushSender.send(payload);
        }

        for (int i = 0; i < 2; i++) {
            String postedAlert = airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS);
            if (postedAlert == null || !postedAlert.startsWith("message")) {
                fail("Unable to receive rich push message.");
                return;
            }
        }

        // Open Navigation drawer
        onView(withId(R.id.drawer_layout))
                .check(matches(isClosed(Gravity.LEFT)))
                .perform(open());

        // Click Message Center
        onView(withId(R.id.nav_view))
                .perform(NavigationViewActions.navigateTo(R.id.nav_message_center));

        // Refresh the list
        onView(withId(R.id.message_list_container))
                .perform(swipeDown());

        // Check that we have 2 messages
        onView(withId(android.R.id.list))
                .check(ViewAssertions.matches(hasChildCount(2)));

        // Open the first message
        onData(instanceOf(RichPushMessage.class))
                .atPosition(0)
                .perform(click());

        // Verify the content
        onWebView()
                .withElement(findElement(Locator.ID, "title"))
                .check(webMatches(getText(), containsString(UAirship.shared().getInbox().getMessages().get(0).getTitle())));

        // Navigate back
        Espresso.pressBack();

        // Verify 1 message is marked read
        assertEquals(1, UAirship.shared().getInbox().getReadCount());
        assertEquals(1, UAirship.shared().getInbox().getUnreadCount());

        // Select the second message
        onData(instanceOf(RichPushMessage.class))
                .atPosition(1)
                .onChildView(withId(R.id.checkbox))
                .perform(click());

        // Mark all as read
        onView(withId(R.id.mark_read))
                .perform(click());

        // Verify all messages read
        assertEquals(UAirship.shared().getInbox().getUnreadCount(), 0);

        // Select each message
        onData(instanceOf(RichPushMessage.class))
                .atPosition(0)
                .onChildView(withId(R.id.checkbox))
                .perform(click());
        onData(instanceOf(RichPushMessage.class))
                .atPosition(1)
                .onChildView(withId(R.id.checkbox))
                .perform(click());

        // Delete all messages
        onView(withId(R.id.delete))
                .perform(click());

        // Verify all the messages are deleted
        assertEquals(0, UAirship.shared().getInbox().getCount());

        // Check that the list is empty
        onView(withId(android.R.id.list))
                .check(ViewAssertions.matches(hasChildCount(0)));
    }
/**
     * Test messages in message center, including marking them as read and deleting the message.
     *
     * @throws Exception
     */
Test messages in message center, including marking them as read and deleting the message.
@throws Exception
Test messages in message center including marking them as read and deleting the message . @throws Exception
@Test
    public void testMessageCenter() throws Exception {
        for (int i = 0; i < 2; i++) {
            RichPushPayload richPushPayload = RichPushPayload.newBuilder()
                                                             .setTitle("message " + i)
                                                             .setHtmlContent("<body id=\"title\">message " + i + "</body>")
                                                             .build();
            PushPayload payload = PushPayload.newChannelPushBuilder(channelId)
                                             .setAlert("message " + i)
                                             .setRichPushMessage(richPushPayload)
                                             .build();
            pushSender.send(payload);
        }
        for (int i = 0; i < 2; i++) {
            String postedAlert = airshipReceiver.postedAlerts.poll(15, TimeUnit.SECONDS);
            if (postedAlert == null || !postedAlert.startsWith("message")) {
                fail("Unable to receive rich push message.");
                return;
            }
        }
        onView(withId(R.id.drawer_layout))
                .check(matches(isClosed(Gravity.LEFT)))
                .perform(open());
        onView(withId(R.id.nav_view))
                .perform(NavigationViewActions.navigateTo(R.id.nav_message_center));
        onView(withId(R.id.message_list_container))
                .perform(swipeDown());
        onView(withId(android.R.id.list))
                .check(ViewAssertions.matches(hasChildCount(2)));
        onData(instanceOf(RichPushMessage.class))
                .atPosition(0)
                .perform(click());
        onWebView()
                .withElement(findElement(Locator.ID, "title"))
                .check(webMatches(getText(), containsString(UAirship.shared().getInbox().getMessages().get(0).getTitle())));
        Espresso.pressBack();
        assertEquals(1, UAirship.shared().getInbox().getReadCount());
        assertEquals(1, UAirship.shared().getInbox().getUnreadCount());
        onData(instanceOf(RichPushMessage.class))
                .atPosition(1)
                .onChildView(withId(R.id.checkbox))
                .perform(click());
        onView(withId(R.id.mark_read))
                .perform(click());
        assertEquals(UAirship.shared().getInbox().getUnreadCount(), 0);
        onData(instanceOf(RichPushMessage.class))
                .atPosition(0)
                .onChildView(withId(R.id.checkbox))
                .perform(click());
        onData(instanceOf(RichPushMessage.class))
                .atPosition(1)
                .onChildView(withId(R.id.checkbox))
                .perform(click());
        onView(withId(R.id.delete))
                .perform(click());
        assertEquals(0, UAirship.shared().getInbox().getCount());
        onView(withId(android.R.id.list))
                .check(ViewAssertions.matches(hasChildCount(0)));
    }
@ Test public void testMessageCenter ( ) throws Exception { for ( int i = 0 ; i < 2 ; i ++ ) { RichPushPayload richPushPayload = RichPushPayload . newBuilder ( ) . setTitle ( "message " + i ) . setHtmlContent ( "<body id=\"title\">message " + i + "</body>" ) . build ( ) ; PushPayload payload = PushPayload . newChannelPushBuilder ( channelId ) . setAlert ( "message " + i ) . setRichPushMessage ( richPushPayload ) . build ( ) ; pushSender . send ( payload ) ; } for ( int i = 0 ; i < 2 ; i ++ ) { String postedAlert = airshipReceiver . postedAlerts . poll ( 15 , TimeUnit . SECONDS ) ; if ( postedAlert == null || ! postedAlert . startsWith ( "message" ) ) { fail ( "Unable to receive rich push message." ) ; return ; } } onView ( withId ( R . id . drawer_layout ) ) . check ( matches ( isClosed ( Gravity . LEFT ) ) ) . perform ( open ( ) ) ; onView ( withId ( R . id . nav_view ) ) . perform ( NavigationViewActions . navigateTo ( R . id . nav_message_center ) ) ; onView ( withId ( R . id . message_list_container ) ) . perform ( swipeDown ( ) ) ; onView ( withId ( android . R . id . list ) ) . check ( ViewAssertions . matches ( hasChildCount ( 2 ) ) ) ; onData ( instanceOf ( RichPushMessage . class ) ) . atPosition ( 0 ) . perform ( click ( ) ) ; onWebView ( ) . withElement ( findElement ( Locator . ID , "title" ) ) . check ( webMatches ( getText ( ) , containsString ( UAirship . shared ( ) . getInbox ( ) . getMessages ( ) . get ( 0 ) . getTitle ( ) ) ) ) ; Espresso . pressBack ( ) ; assertEquals ( 1 , UAirship . shared ( ) . getInbox ( ) . getReadCount ( ) ) ; assertEquals ( 1 , UAirship . shared ( ) . getInbox ( ) . getUnreadCount ( ) ) ; onData ( instanceOf ( RichPushMessage . class ) ) . atPosition ( 1 ) . onChildView ( withId ( R . id . checkbox ) ) . perform ( click ( ) ) ; onView ( withId ( R . id . mark_read ) ) . perform ( click ( ) ) ; assertEquals ( UAirship . shared ( ) . getInbox ( ) . getUnreadCount ( ) , 0 ) ; onData ( instanceOf ( RichPushMessage . class ) ) . atPosition ( 0 ) . onChildView ( withId ( R . id . checkbox ) ) . perform ( click ( ) ) ; onData ( instanceOf ( RichPushMessage . class ) ) . atPosition ( 1 ) . onChildView ( withId ( R . id . checkbox ) ) . perform ( click ( ) ) ; onView ( withId ( R . id . delete ) ) . perform ( click ( ) ) ; assertEquals ( 0 , UAirship . shared ( ) . getInbox ( ) . getCount ( ) ) ; onView ( withId ( android . R . id . list ) ) . check ( ViewAssertions . matches ( hasChildCount ( 0 ) ) ) ; }
Test messages in message center, including marking them as read and deleting the message.
Test messages in message center including marking them as read and deleting the message .
// Open Navigation drawer // Click Message Center // Refresh the list // Check that we have 2 messages // Open the first message // Verify the content // Navigate back // Verify 1 message is marked read // Select the second message // Mark all as read // Verify all messages read // Select each message // Delete all messages // Verify all the messages are deleted // Check that the list is empty