diff options
| author | 2022-07-25 16:34:39 +0000 | |
|---|---|---|
| committer | 2022-07-25 16:34:39 +0000 | |
| commit | fa50a425bf408ffc80b52de5212c6e6ca677e098 (patch) | |
| tree | 5e7ba5b5627ef047a0779d301eef50044c2e78f3 | |
| parent | 00be659711036e176899dd35fe445bf31d2dc98c (diff) | |
| parent | 9f572750a941df401f6d66e32a9314586db22dbd (diff) | |
Merge "[Home Controls] Add null safety to comparator." into tm-qpr-dev am: 9f572750a9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19381352
Change-Id: Ifa846a289723a8b9eb11d5707161c9dca0f4720c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt | 2 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/controls/management/AppAdapterTest.kt | 84 |
2 files changed, 85 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt b/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt index a174ed0312c8..2389ad134c55 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt @@ -62,7 +62,7 @@ class AppAdapter( backgroundExecutor.execute { val collator = Collator.getInstance(resources.configuration.locales[0]) val localeComparator = compareBy<ControlsServiceInfo, CharSequence>(collator) { - it.loadLabel() + it.loadLabel() ?: "" } listOfServices = serviceInfos.sortedWith(localeComparator) uiExecutor.execute(::notifyDataSetChanged) diff --git a/packages/SystemUI/tests/src/com/android/systemui/controls/management/AppAdapterTest.kt b/packages/SystemUI/tests/src/com/android/systemui/controls/management/AppAdapterTest.kt new file mode 100644 index 000000000000..1e4a9e42cce1 --- /dev/null +++ b/packages/SystemUI/tests/src/com/android/systemui/controls/management/AppAdapterTest.kt @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2022 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.controls.management + +import android.content.ComponentName +import android.content.res.Resources +import android.testing.AndroidTestingRunner +import android.testing.TestableLooper +import android.view.LayoutInflater +import androidx.test.filters.SmallTest +import com.android.settingslib.core.lifecycle.Lifecycle +import com.android.systemui.SysuiTestCase +import com.android.systemui.controls.ControlsServiceInfo +import com.android.systemui.util.concurrency.FakeExecutor +import com.android.systemui.util.mockito.any +import com.android.systemui.util.time.FakeSystemClock +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.mockito.Mock +import org.mockito.Mockito.mock +import org.mockito.Mockito.verify +import org.mockito.Mockito.`when` +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidTestingRunner::class) +@TestableLooper.RunWithLooper(setAsMainLooper = true) +class AppAdapterTest : SysuiTestCase() { + private val fakeSystemClock = FakeSystemClock() + private val backgroundExecutor = FakeExecutor(fakeSystemClock) + private val uiExecutor = FakeExecutor(fakeSystemClock) + @Mock lateinit var lifecycle: Lifecycle + @Mock lateinit var controlsListingController: ControlsListingController + @Mock lateinit var layoutInflater: LayoutInflater + @Mock lateinit var onAppSelected: (ComponentName?) -> Unit + @Mock lateinit var favoritesRenderer: FavoritesRenderer + val resources: Resources = context.resources + lateinit var adapter: AppAdapter + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + adapter = AppAdapter(backgroundExecutor, + uiExecutor, + lifecycle, + controlsListingController, + layoutInflater, + onAppSelected, + favoritesRenderer, + resources) + } + + @Test + fun testOnServicesUpdated_nullLoadLabel() { + val captor = ArgumentCaptor + .forClass(ControlsListingController.ControlsListingCallback::class.java) + val controlsServiceInfo = mock(ControlsServiceInfo::class.java) + val serviceInfo = listOf(controlsServiceInfo) + `when`(controlsServiceInfo.loadLabel()).thenReturn(null) + verify(controlsListingController).observe(any(Lifecycle::class.java), captor.capture()) + + captor.value.onServicesUpdated(serviceInfo) + backgroundExecutor.runAllReady() + uiExecutor.runAllReady() + + assertThat(adapter.itemCount).isEqualTo(serviceInfo.size) + } +} |