Merge "[RONs] convert ColorizedFgsCoordinatorTest to kotlin" into main
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.java
deleted file mode 100644
index 544d201..0000000
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.statusbar.notification.collection.coordinator;
-
-import static android.app.Notification.FLAG_FOREGROUND_SERVICE;
-import static android.app.Notification.FLAG_PROMOTED_ONGOING;
-import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
-import static android.app.NotificationManager.IMPORTANCE_HIGH;
-import static android.app.NotificationManager.IMPORTANCE_MIN;
-
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertTrue;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-
-import android.app.Notification;
-import android.app.PendingIntent;
-import android.app.Person;
-import android.content.Intent;
-import android.graphics.Color;
-import android.os.UserHandle;
-import android.platform.test.annotations.DisableFlags;
-import android.platform.test.annotations.EnableFlags;
-import android.testing.TestableLooper;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import com.android.systemui.SysuiTestCase;
-import com.android.systemui.statusbar.notification.collection.NotifPipeline;
-import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder;
-import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter;
-import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
-import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-@TestableLooper.RunWithLooper
-public class ColorizedFgsCoordinatorTest extends SysuiTestCase {
-
-    private static final int NOTIF_USER_ID = 0;
-    @Mock private NotifPipeline mNotifPipeline;
-
-    private NotificationEntryBuilder mEntryBuilder;
-    private ColorizedFgsCoordinator mColorizedFgsCoordinator;
-    private NotifSectioner mFgsSection;
-
-    @Before
-    public void setup() {
-        MockitoAnnotations.initMocks(this);
-        allowTestableLooperAsMainThread();
-
-        mColorizedFgsCoordinator = new ColorizedFgsCoordinator();
-
-        mEntryBuilder = new NotificationEntryBuilder()
-                .setUser(new UserHandle(NOTIF_USER_ID));
-
-        mColorizedFgsCoordinator.attach(mNotifPipeline);
-
-        mFgsSection = mColorizedFgsCoordinator.getSectioner();
-    }
-
-    @Test
-    public void testIncludeFGSInSection_importanceDefault() {
-        // GIVEN the notification represents a colorized foreground service with > min importance
-        mEntryBuilder
-                .setFlag(mContext, FLAG_FOREGROUND_SERVICE, true)
-                .setImportance(IMPORTANCE_DEFAULT)
-                .modifyNotification(mContext)
-                .setColorized(true).setColor(Color.WHITE);
-
-        // THEN the entry is in the fgs section
-        assertTrue(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    public void testDiscludeFGSInSection_importanceMin() {
-        // GIVEN the notification represents a colorized foreground service with min importance
-        mEntryBuilder
-                .setFlag(mContext, FLAG_FOREGROUND_SERVICE, true)
-                .setImportance(IMPORTANCE_MIN)
-                .modifyNotification(mContext)
-                .setColorized(true).setColor(Color.WHITE);
-
-        // THEN the entry is NOT in the fgs section
-        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    public void testDiscludeNonFGSInSection() {
-        // GIVEN the notification represents a colorized notification with high importance that
-        // is NOT a foreground service
-        mEntryBuilder
-                .setImportance(IMPORTANCE_HIGH)
-                .setFlag(mContext, FLAG_FOREGROUND_SERVICE, false)
-                .modifyNotification(mContext).setColorized(false);
-
-        // THEN the entry is NOT in the fgs section
-        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    public void testIncludeCallInSection_importanceDefault() {
-        // GIVEN the notification represents a call with > min importance
-        mEntryBuilder
-                .setImportance(IMPORTANCE_DEFAULT)
-                .modifyNotification(mContext)
-                .setStyle(makeCallStyle());
-
-        // THEN the entry is in the fgs section
-        assertTrue(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    public void testDiscludeCallInSection_importanceMin() {
-        // GIVEN the notification represents a call with min importance
-        mEntryBuilder
-                .setImportance(IMPORTANCE_MIN)
-                .modifyNotification(mContext)
-                .setStyle(makeCallStyle());
-
-        // THEN the entry is NOT in the fgs section
-        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
-    public void testIncludePromotedOngoingInSection_flagEnabled() {
-        // GIVEN the notification has FLAG_PROMOTED_ONGOING
-        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);
-
-        // THEN the entry is in the fgs section
-        assertTrue(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
-    public void testDiscludePromotedOngoingInSection_flagDisabled() {
-        // GIVEN the notification has FLAG_PROMOTED_ONGOING
-        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);
-
-        // THEN the entry is NOT in the fgs section
-        assertFalse(mFgsSection.isInSection(mEntryBuilder.build()));
-    }
-
-    @Test
-    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
-    public void promoterSelectsPromotedOngoing_flagEnabled() {
-        ArgumentCaptor<NotifPromoter> captor = ArgumentCaptor.forClass(NotifPromoter.class);
-        verify(mNotifPipeline).addPromoter(captor.capture());
-        NotifPromoter promoter = captor.getValue();
-
-        // GIVEN the notification has FLAG_PROMOTED_ONGOING
-        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, true);
-
-        // THEN the entry is promoted to top level
-        assertTrue(promoter.shouldPromoteToTopLevel(mEntryBuilder.build()));
-    }
-
-    @Test
-    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
-    public void promoterIgnoresNonPromotedOngoing_flagEnabled() {
-        ArgumentCaptor<NotifPromoter> captor = ArgumentCaptor.forClass(NotifPromoter.class);
-        verify(mNotifPipeline).addPromoter(captor.capture());
-        NotifPromoter promoter = captor.getValue();
-
-        // GIVEN the notification does not have FLAG_PROMOTED_ONGOING
-        mEntryBuilder.setFlag(mContext, FLAG_PROMOTED_ONGOING, false);
-
-        // THEN the entry is NOT promoted to top level
-        assertFalse(promoter.shouldPromoteToTopLevel(mEntryBuilder.build()));
-    }
-
-    @Test
-    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
-    public void noPromoterAdded_flagDisabled() {
-        verify(mNotifPipeline, never()).addPromoter(any());
-    }
-
-    private Notification.CallStyle makeCallStyle() {
-        final PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0,
-                new Intent("action"), PendingIntent.FLAG_IMMUTABLE);
-        final Person person = new Person.Builder().setName("person").build();
-        return Notification.CallStyle.forIncomingCall(person, pendingIntent, pendingIntent);
-    }
-}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.kt
new file mode 100644
index 0000000..e93c742
--- /dev/null
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/collection/coordinator/ColorizedFgsCoordinatorTest.kt
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.systemui.statusbar.notification.collection.coordinator
+
+import android.app.Notification
+import android.app.NotificationManager
+import android.app.PendingIntent
+import android.app.Person
+import android.content.Intent
+import android.graphics.Color
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.testing.TestableLooper.RunWithLooper
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.kosmos.useUnconfinedTestDispatcher
+import com.android.systemui.statusbar.notification.collection.buildEntry
+import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter
+import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner
+import com.android.systemui.statusbar.notification.collection.notifPipeline
+import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi
+import com.android.systemui.testKosmos
+import com.android.systemui.util.mockito.withArgCaptor
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Before
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.kotlin.any
+import org.mockito.kotlin.never
+import org.mockito.kotlin.verify
+
+@SmallTest
+@RunWith(AndroidJUnit4::class)
+@RunWithLooper
+class ColorizedFgsCoordinatorTest : SysuiTestCase() {
+    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
+    private val notifPipeline
+        get() = kosmos.notifPipeline
+
+    private lateinit var colorizedFgsCoordinator: ColorizedFgsCoordinator
+    private lateinit var sectioner: NotifSectioner
+
+    @Before
+    fun setup() {
+        allowTestableLooperAsMainThread()
+
+        colorizedFgsCoordinator = ColorizedFgsCoordinator()
+        colorizedFgsCoordinator.attach(notifPipeline)
+        sectioner = colorizedFgsCoordinator.sectioner
+    }
+
+    @Test
+    fun testIncludeFGSInSection_importanceDefault() {
+        // GIVEN the notification represents a colorized foreground service with > min importance
+        val entry = buildEntry {
+            setFlag(mContext, Notification.FLAG_FOREGROUND_SERVICE, true)
+            setImportance(NotificationManager.IMPORTANCE_DEFAULT)
+            modifyNotification(mContext).setColorized(true).setColor(Color.WHITE)
+        }
+
+        // THEN the entry is in the fgs section
+        assertTrue(sectioner.isInSection(entry))
+    }
+
+    @Test
+    fun testDiscludeFGSInSection_importanceMin() {
+        // GIVEN the notification represents a colorized foreground service with min importance
+        val entry = buildEntry {
+            setFlag(mContext, Notification.FLAG_FOREGROUND_SERVICE, true)
+            setImportance(NotificationManager.IMPORTANCE_MIN)
+            modifyNotification(mContext).setColorized(true).setColor(Color.WHITE)
+        }
+
+        // THEN the entry is NOT in the fgs section
+        assertFalse(sectioner.isInSection(entry))
+    }
+
+    @Test
+    fun testDiscludeNonFGSInSection() {
+        // GIVEN the notification represents a colorized notification with high importance that
+        // is NOT a foreground service
+        val entry = buildEntry {
+            setImportance(NotificationManager.IMPORTANCE_HIGH)
+            setFlag(mContext, Notification.FLAG_FOREGROUND_SERVICE, false)
+            modifyNotification(mContext).setColorized(false)
+        }
+
+        // THEN the entry is NOT in the fgs section
+        assertFalse(sectioner.isInSection(entry))
+    }
+
+    @Test
+    fun testIncludeCallInSection_importanceDefault() {
+        // GIVEN the notification represents a call with > min importance
+        val entry = buildEntry {
+            setImportance(NotificationManager.IMPORTANCE_DEFAULT)
+            modifyNotification(mContext).setStyle(makeCallStyle())
+        }
+
+        // THEN the entry is in the fgs section
+        assertTrue(sectioner.isInSection(entry))
+    }
+
+    @Test
+    fun testDiscludeCallInSection_importanceMin() {
+        // GIVEN the notification represents a call with min importance
+        val entry = buildEntry {
+            setImportance(NotificationManager.IMPORTANCE_MIN)
+            modifyNotification(mContext).setStyle(makeCallStyle())
+        }
+
+        // THEN the entry is NOT in the fgs section
+        assertFalse(sectioner.isInSection(entry))
+    }
+
+    @Test
+    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
+    fun testIncludePromotedOngoingInSection_flagEnabled() {
+        // GIVEN the notification has FLAG_PROMOTED_ONGOING
+        val entry = buildEntry { setFlag(mContext, Notification.FLAG_PROMOTED_ONGOING, true) }
+
+        // THEN the entry is in the fgs section
+        assertTrue(sectioner.isInSection(entry))
+    }
+
+    @Test
+    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
+    fun testDiscludePromotedOngoingInSection_flagDisabled() {
+        // GIVEN the notification has FLAG_PROMOTED_ONGOING
+        val entry = buildEntry { setFlag(mContext, Notification.FLAG_PROMOTED_ONGOING, true) }
+
+        // THEN the entry is NOT in the fgs section
+        assertFalse(sectioner.isInSection(entry))
+    }
+
+    @Test
+    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
+    fun promoterSelectsPromotedOngoing_flagEnabled() {
+        val promoter: NotifPromoter = withArgCaptor { verify(notifPipeline).addPromoter(capture()) }
+
+        // GIVEN the notification has FLAG_PROMOTED_ONGOING
+        val entry = buildEntry { setFlag(mContext, Notification.FLAG_PROMOTED_ONGOING, true) }
+
+        // THEN the entry is promoted to top level
+        assertTrue(promoter.shouldPromoteToTopLevel(entry))
+    }
+
+    @Test
+    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
+    fun promoterIgnoresNonPromotedOngoing_flagEnabled() {
+        val promoter: NotifPromoter = withArgCaptor { verify(notifPipeline).addPromoter(capture()) }
+
+        // GIVEN the notification does not have FLAG_PROMOTED_ONGOING
+        val entry = buildEntry { setFlag(mContext, Notification.FLAG_PROMOTED_ONGOING, false) }
+
+        // THEN the entry is NOT promoted to top level
+        assertFalse(promoter.shouldPromoteToTopLevel(entry))
+    }
+
+    @Test
+    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
+    fun noPromoterAdded_flagDisabled() {
+        verify(notifPipeline, never()).addPromoter(any())
+    }
+
+    private fun makeCallStyle(): Notification.CallStyle {
+        val pendingIntent =
+            PendingIntent.getBroadcast(mContext, 0, Intent("action"), PendingIntent.FLAG_IMMUTABLE)
+        val person = Person.Builder().setName("person").build()
+        return Notification.CallStyle.forOngoingCall(person, pendingIntent)
+    }
+
+    companion object {
+        private const val NOTIF_USER_ID = 0
+    }
+}
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/collection/EntryUtil.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/collection/EntryUtil.kt
index 8b4de2b..05f1c0b 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/collection/EntryUtil.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/collection/EntryUtil.kt
@@ -33,3 +33,6 @@
 fun getAttachState(entry: ListEntry): ListAttachState {
     return entry.attachState
 }
+
+fun buildEntry(block: NotificationEntryBuilder.() -> Unit) =
+    NotificationEntryBuilder().apply(block).build()