FileDocCategorySizeDatePackage
NotificationCompatWearableExtenderTest.javaAPI DocAndroid 5.1 API12358Thu Mar 12 22:22:56 GMT 2015android.support.v4.app

NotificationCompatWearableExtenderTest

public class NotificationCompatWearableExtenderTest extends android.test.AndroidTestCase
Tests for {@link android.support.v4.app.NotificationCompat.WearableExtender}.

Fields Summary
public static final int
CUSTOM_CONTENT_HEIGHT_DP
private android.app.PendingIntent
mPendingIntent
private int
mCustomContentHeightPx
Constructors Summary
Methods Summary
private voidassertActionsEqual(Notification.Action real, NotificationCompat.Action compat)

        assertEquals(real.icon, compat.icon);
        assertEquals(real.title, compat.title);
        assertEquals(real.actionIntent, compat.actionIntent);
        assertRemoteInputsEquals(real.getRemoteInputs(), compat.getRemoteInputs());
        assertBundlesEqual(real.getExtras(), compat.getExtras());
    
private voidassertActionsEquals(java.util.List realArray, java.util.List compatArray)

        assertEquals(realArray.size(), compatArray.size());
        for (int i = 0; i < realArray.size(); i++) {
            assertActionsEqual(realArray.get(i), compatArray.get(i));
        }
    
private voidassertBundlesEqual(android.os.Bundle bundle1, android.os.Bundle bundle2)

        assertEquals(bundle1.size(), bundle2.size());
        for (String key : bundle1.keySet()) {
            Object value1 = bundle1.get(key);
            Object value2 = bundle2.get(key);
            if (value1 instanceof Bundle && value2 instanceof Bundle) {
                assertBundlesEqual((Bundle) value1, (Bundle) value2);
            } else {
                assertEquals(value1, value2);
            }
        }
    
private voidassertCharSequencesEquals(java.lang.CharSequence[] array1, java.lang.CharSequence[] array2)

        if (!Arrays.deepEquals(array1, array2)) {
            fail("Arrays not equal: " + Arrays.toString(array1) + " != " + Arrays.toString(array2));
        }
    
private voidassertExtendersEqual(Notification.WearableExtender real, NotificationCompat.WearableExtender compat)

        assertActionsEquals(real.getActions(), compat.getActions());
        assertEquals(real.getContentIntentAvailableOffline(),
                compat.getContentIntentAvailableOffline());
        assertEquals(real.getHintHideIcon(), compat.getHintHideIcon());
        assertEquals(real.getHintShowBackgroundOnly(), compat.getHintShowBackgroundOnly());
        assertEquals(real.getStartScrollBottom(), compat.getStartScrollBottom());
        assertEquals(real.getDisplayIntent(), compat.getDisplayIntent());
        assertPagesEquals(real.getPages(), compat.getPages());
        assertEquals(real.getBackground(), compat.getBackground());
        assertEquals(real.getContentIcon(), compat.getContentIcon());
        assertEquals(real.getContentIconGravity(), compat.getContentIconGravity());
        assertEquals(real.getContentAction(), compat.getContentAction());
        assertEquals(real.getCustomSizePreset(), compat.getCustomSizePreset());
        assertEquals(real.getCustomContentHeight(), compat.getCustomContentHeight());
        assertEquals(real.getGravity(), compat.getGravity());
    
private voidassertNotificationsEqual(android.app.Notification n1, android.app.Notification n2)

        assertEquals(n1.icon, n2.icon);
        assertBundlesEqual(n1.extras, n2.extras);
        assertExtendersEqual(new Notification.WearableExtender(n1),
                new NotificationCompat.WearableExtender(n2));
    
private voidassertPagesEquals(java.util.List pages1, java.util.List pages2)

        assertEquals(pages1.size(), pages2.size());
        for (int i = 0; i < pages1.size(); i++) {
            assertNotificationsEqual(pages1.get(i), pages2.get(i));
        }
    
private voidassertRemoteInputsEqual(android.app.RemoteInput real, RemoteInput compat)

        assertEquals(real.getResultKey(), compat.getResultKey());
        assertEquals(real.getLabel(), compat.getLabel());
        assertCharSequencesEquals(real.getChoices(), compat.getChoices());
        assertEquals(real.getAllowFreeFormInput(), compat.getAllowFreeFormInput());
        assertBundlesEqual(real.getExtras(), compat.getExtras());
    
private voidassertRemoteInputsEquals(android.app.RemoteInput[] realArray, RemoteInput[] compatArray)

        assertEquals(realArray == null, compatArray == null);
        if (realArray != null) {
            assertEquals(realArray.length, compatArray.length);
            for (int i = 0; i < realArray.length; i++) {
                assertRemoteInputsEqual(realArray[i], compatArray[i]);
            }
        }
    
protected voidsetUp()


    
         
        super.setUp();

        mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);

        mCustomContentHeightPx = Math.round(getContext().getResources().getDisplayMetrics().density
                * CUSTOM_CONTENT_HEIGHT_DP);
    
public voidtestCompatReadRealEmptyValue()

        Notification.WearableExtender realExtender =
                new Notification.WearableExtender();
        Notification notif = new Notification.Builder(getContext())
                .extend(realExtender)
                .build();

        assertExtendersEqual(realExtender, new NotificationCompat.WearableExtender(notif));
        assertExtendersEqual(new Notification.WearableExtender(notif),
                new NotificationCompat.WearableExtender(notif));
    
public voidtestCompatReadRealValue()

        android.app.RemoteInput.Builder remoteInput = new android.app.RemoteInput.Builder(
                "result_key1")
                .setLabel("label")
                .setChoices(new CharSequence[] {"choice 1", "choice 2"});
        remoteInput.getExtras().putString("remoteinput_string", "test");
        Notification.Action.Builder action2 = new Notification.Action.Builder(
                R.drawable.action_icon, "Test title", mPendingIntent)
                .addRemoteInput(remoteInput.build())
                .extend(new Notification.Action.WearableExtender()
                        .setAvailableOffline(false)
                        .setInProgressLabel("In Progress Label")
                        .setConfirmLabel("Confirmation Label")
                        .setCancelLabel("Cancelation Label"));
        // Add an arbitrary key/value.
        action2.getExtras().putFloat("action_float", 10.5f);

        Notification page2 = new Notification.Builder(getContext())
                .setContentTitle("page2 title")
                .extend(new Notification.WearableExtender()
                        .setContentIcon(R.drawable.content_icon))
                .build();

        Notification.WearableExtender realExtender =
                new Notification.WearableExtender()
                        .addAction(new Notification.Action(R.drawable.action_icon2, "Action1",
                                mPendingIntent))
                        .addAction(action2.build())
                        .setContentIntentAvailableOffline(false)
                        .setHintHideIcon(true)
                        .setHintShowBackgroundOnly(true)
                        .setStartScrollBottom(true)
                        .setDisplayIntent(mPendingIntent)
                        .addPage(page2)
                        .setContentIcon(R.drawable.content_icon2)
                        .setContentIconGravity(Gravity.START)
                        .setContentAction(5 /* arbitrary content action index */)
                        .setCustomSizePreset(NotificationCompat.WearableExtender.SIZE_MEDIUM)
                        .setCustomContentHeight(mCustomContentHeightPx)
                        .setGravity(Gravity.TOP);

        Notification notif = new Notification.Builder(getContext())
                .extend(realExtender).build();
        assertExtendersEqual(realExtender, new NotificationCompat.WearableExtender(notif));
        assertExtendersEqual(new Notification.WearableExtender(notif),
                new NotificationCompat.WearableExtender(notif));
    
public voidtestEmptyEquals()

        assertExtendersEqual(new Notification.WearableExtender(),
                new NotificationCompat.WearableExtender());
    
public voidtestRealReadCompatEmptyValue()

        NotificationCompat.WearableExtender compatExtender =
                new NotificationCompat.WearableExtender();
        Notification notif = new NotificationCompat.Builder(getContext())
                .extend(compatExtender)
                .build();

        assertExtendersEqual(new Notification.WearableExtender(notif), compatExtender);
        assertExtendersEqual(new Notification.WearableExtender(notif),
                new NotificationCompat.WearableExtender(notif));
    
public voidtestRealReadCompatValue()

        RemoteInput.Builder remoteInput = new RemoteInput.Builder("result_key1")
                .setLabel("label")
                .setChoices(new CharSequence[] {"choice 1", "choice 2"});
        remoteInput.getExtras().putString("remoteinput_string", "test");
        NotificationCompat.Action.Builder action2 = new NotificationCompat.Action.Builder(
                R.drawable.action_icon, "Test title", mPendingIntent)
                .addRemoteInput(remoteInput.build())
                .extend(new NotificationCompat.Action.WearableExtender()
                        .setAvailableOffline(false)
                        .setInProgressLabel("In Progress Label")
                        .setConfirmLabel("Confirmation Label")
                        .setCancelLabel("Cancelation Label"));
        // Add an arbitrary key/value.
        action2.getExtras().putFloat("action_float", 10.5f);

        Notification page2 = new Notification.Builder(getContext())
                .setContentTitle("page2 title")
                .extend(new Notification.WearableExtender()
                        .setContentIcon(R.drawable.content_icon))
                .build();

        NotificationCompat.WearableExtender compatExtender =
                new NotificationCompat.WearableExtender()
                        .addAction(new NotificationCompat.Action(R.drawable.action_icon2, "Action1",
                                mPendingIntent))
                        .addAction(action2.build())
                        .setContentIntentAvailableOffline(false)
                        .setHintHideIcon(true)
                        .setHintShowBackgroundOnly(true)
                        .setStartScrollBottom(true)
                        .setDisplayIntent(mPendingIntent)
                        .addPage(page2)
                        .setContentIcon(R.drawable.content_icon2)
                        .setContentIconGravity(Gravity.START)
                        .setContentAction(5 /* arbitrary content action index */)
                        .setCustomSizePreset(NotificationCompat.WearableExtender.SIZE_MEDIUM)
                        .setCustomContentHeight(mCustomContentHeightPx)
                        .setGravity(Gravity.TOP);

        Notification notif = new NotificationCompat.Builder(getContext())
                .extend(compatExtender).build();
        assertExtendersEqual(new Notification.WearableExtender(notif), compatExtender);
        assertExtendersEqual(new Notification.WearableExtender(notif),
                new NotificationCompat.WearableExtender(notif));