Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82a9cd16 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move remaining tests over to using NotificationEntryBuilder"

parents b0e54c56 636c379f
Loading
Loading
Loading
Loading
+7 −27
Original line number Diff line number Diff line
@@ -148,35 +148,11 @@ public final class NotificationEntry {
    private boolean mPulseSupressed;

    public NotificationEntry(
            StatusBarNotification sbn,
            @NonNull StatusBarNotification sbn,
            @NonNull Ranking ranking) {
        this(sbn, ranking, false);
    }

    private NotificationEntry(
            StatusBarNotification sbn,
            Ranking ranking,
            boolean isTest) {
        this.key = sbn.getKey();
        this.notification = sbn;

        // TODO: Update tests to no longer need to pass null ranking
        if (ranking != null) {
        setNotification(sbn);
        setRanking(ranking);
        } else if (!isTest) {
            throw new IllegalArgumentException("Ranking cannot be null");
        }
    }

    /**
     * Method for old tests that build NotificationEntries without a ranking.
     *
     * @deprecated Use NotificationEntryBuilder instead.
     */
    @VisibleForTesting
    @Deprecated
    public static NotificationEntry buildForTest(StatusBarNotification sbn) {
        return new NotificationEntry(sbn, null, true);
    }

    /** The key for this notification. Guaranteed to be immutable and unique */
@@ -218,6 +194,10 @@ public final class NotificationEntry {
     * TODO: Make this package-private
     */
    public void setRanking(@NonNull Ranking ranking) {
        if (!ranking.getKey().equals(key)) {
            throw new IllegalArgumentException("New key " + ranking.getKey()
                    + " doesn't match existing key " + key);
        }
        mRanking = ranking;
    }

+6 −2
Original line number Diff line number Diff line
@@ -393,8 +393,12 @@ public class ForegroundServiceControllerTest extends SysuiTestCase {
    }

    private void entryRemoved(StatusBarNotification notification) {
        mEntryListener.onEntryRemoved(NotificationEntry.buildForTest(notification),
                null, false);
        mEntryListener.onEntryRemoved(
                new NotificationEntryBuilder()
                        .setSbn(notification)
                        .build(),
                null,
                false);
    }

    private void entryAdded(StatusBarNotification notification, int importance) {
+14 −12
Original line number Diff line number Diff line
@@ -17,19 +17,17 @@
package com.android.systemui;

import static com.android.systemui.ForegroundServiceLifetimeExtender.MIN_FGS_TIME_MS;
import static com.android.systemui.statusbar.NotificationEntryHelper.modifySbn;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.app.Notification;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.StatusBarNotification;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;

import org.junit.Before;
@@ -40,7 +38,6 @@ import org.junit.runner.RunWith;
@SmallTest
public class ForegroundServiceNotificationListenerTest extends SysuiTestCase {
    private ForegroundServiceLifetimeExtender mExtender = new ForegroundServiceLifetimeExtender();
    private StatusBarNotification mSbn;
    private NotificationEntry mEntry;
    private Notification mNotif;

@@ -52,10 +49,9 @@ public class ForegroundServiceNotificationListenerTest extends SysuiTestCase {
                .setContentText("Text")
                .build();

        mSbn = mock(StatusBarNotification.class);
        when(mSbn.getNotification()).thenReturn(mNotif);

        mEntry = new NotificationEntry(mSbn, mock(Ranking.class));
        mEntry = new NotificationEntryBuilder()
                .setNotification(mNotif)
                .build();
    }

    /**
@@ -66,21 +62,27 @@ public class ForegroundServiceNotificationListenerTest extends SysuiTestCase {
        // Extend the lifetime of a FGS notification iff it has not been visible
        // for the minimum time
        mNotif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
        when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis());
        modifySbn(mEntry)
                .setPostTime(System.currentTimeMillis())
                .build();
        assertTrue(mExtender.shouldExtendLifetime(mEntry));
    }

    @Test
    public void testShouldExtendLifetime_shouldNot_foreground() {
        mNotif.flags |= Notification.FLAG_FOREGROUND_SERVICE;
        when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1);
        modifySbn(mEntry)
                .setPostTime(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1)
                .build();
        assertFalse(mExtender.shouldExtendLifetime(mEntry));
    }

    @Test
    public void testShouldExtendLifetime_shouldNot_notForeground() {
        mNotif.flags = 0;
        when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1);
        modifySbn(mEntry)
                .setPostTime(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1)
                .build();
        assertFalse(mExtender.shouldExtendLifetime(mEntry));
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.bubbles.BubbleData.TimeSource;
import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.NotificationTestHelper;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;

@@ -878,7 +879,7 @@ public class BubbleDataTest extends SysuiTestCase {
        when(sbn.getNotification()).thenReturn(notification);

        // NotificationEntry -> StatusBarNotification -> Notification -> BubbleMetadata
        return NotificationEntry.buildForTest(sbn);
        return new NotificationEntryBuilder().setSbn(sbn).build();
    }

    private void setCurrentTime(long time) {
+4 −21
Original line number Diff line number Diff line
@@ -19,19 +19,16 @@ package com.android.systemui.bubbles;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

import android.app.Notification;
import android.os.Bundle;
import android.service.notification.NotificationListenerService.Ranking;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;

import org.junit.Before;
@@ -44,8 +41,6 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class BubbleTest extends SysuiTestCase {
    @Mock
    private StatusBarNotification mStatusBarNotification;
    @Mock
    private Notification mNotif;

@@ -57,27 +52,15 @@ public class BubbleTest extends SysuiTestCase {
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        when(mStatusBarNotification.getKey()).thenReturn("key");
        when(mStatusBarNotification.getNotification()).thenReturn(mNotif);
        when(mStatusBarNotification.getUser()).thenReturn(new UserHandle(0));
        mExtras = new Bundle();
        mNotif.extras = mExtras;

        mEntry = NotificationEntry.buildForTest(mStatusBarNotification);
        mEntry = new NotificationEntryBuilder()
                .setNotification(mNotif)
                .build();
        mBubble = new Bubble(mContext, mEntry);
    }

    @Test
    public void testInitialization() {
        final Ranking ranking = new Ranking();

        final NotificationEntry entry = new NotificationEntry(mStatusBarNotification, ranking);

        assertEquals("key", entry.key());
        assertEquals(mStatusBarNotification, entry.sbn());
        assertEquals(ranking, entry.ranking());
    }

    @Test
    public void testGetUpdateMessage_default() {
        final String msg = "Hello there!";
Loading