Loading packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt +9 −9 Original line number Diff line number Diff line Loading @@ -77,8 +77,8 @@ constructor( controller.setSuggestionCardIds(storeLocations.toSet()) } private val binder: IWalletContextualLocationsService.Stub = object : IWalletContextualLocationsService.Stub() { private val binder: IWalletContextualLocationsService.Stub = object : IWalletContextualLocationsService.Stub() { override fun addWalletCardsUpdatedListener(listener: IWalletCardsUpdatedListener) { addWalletCardsUpdatedListenerInternal(listener) } Loading packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt +44 −38 Original line number Diff line number Diff line Loading @@ -12,12 +12,9 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before Loading @@ -41,7 +38,8 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private lateinit var underTest: WalletContextualLocationsService private lateinit var testScope: TestScope private var listenerRegisteredCount: Int = 0 private val listener: IWalletCardsUpdatedListener.Stub = object : IWalletCardsUpdatedListener.Stub() { private val listener: IWalletCardsUpdatedListener.Stub = object : IWalletCardsUpdatedListener.Stub() { override fun registerNewWalletCards(cards: List<WalletCard?>) { listenerRegisteredCount++ } Loading @@ -60,26 +58,30 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { featureFlags.set(Flags.ENABLE_WALLET_CONTEXTUAL_LOYALTY_CARDS, true) listenerRegisteredCount = 0 underTest = WalletContextualLocationsService(controller, featureFlags, testScope.backgroundScope) underTest = WalletContextualLocationsService(controller, featureFlags, testScope.backgroundScope) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun addListener() = testScope.runTest { fun addListener() = testScope.runTest { underTest.addWalletCardsUpdatedListenerInternal(listener) assertThat(listenerRegisteredCount).isEqualTo(1) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun addStoreLocations() = testScope.runTest { fun addStoreLocations() = testScope.runTest { underTest.onWalletContextualLocationsStateUpdatedInternal(ArrayList<String>()) verify(controller, times(1)).setSuggestionCardIds(anySet()) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun updateListenerAndLocationsState() = testScope.runTest { fun updateListenerAndLocationsState() = testScope.runTest { // binds to the service and adds a listener val underTestStub = getInterface underTestStub.addWalletCardsUpdatedListener(listener) Loading @@ -102,8 +104,10 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private val fakeWalletCards: MutableStateFlow<List<WalletCard>> get() { val intent = Intent(getContext(), WalletContextualLocationsService::class.java) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val walletCards: ArrayList<WalletCard> = ArrayList<WalletCard>() walletCards.add(WalletCard.Builder("card1", icon, "card", pi).build()) walletCards.add(WalletCard.Builder("card2", icon, "card", pi).build()) Loading @@ -113,8 +117,10 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private val updatedFakeWalletCards: List<WalletCard> get() { val intent = Intent(getContext(), WalletContextualLocationsService::class.java) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val walletCards: ArrayList<WalletCard> = ArrayList<WalletCard>() walletCards.add(WalletCard.Builder("card3", icon, "card", pi).build()) return walletCards Loading Loading
packages/SystemUI/src/com/android/systemui/wallet/controller/WalletContextualLocationsService.kt +9 −9 Original line number Diff line number Diff line Loading @@ -77,8 +77,8 @@ constructor( controller.setSuggestionCardIds(storeLocations.toSet()) } private val binder: IWalletContextualLocationsService.Stub = object : IWalletContextualLocationsService.Stub() { private val binder: IWalletContextualLocationsService.Stub = object : IWalletContextualLocationsService.Stub() { override fun addWalletCardsUpdatedListener(listener: IWalletCardsUpdatedListener) { addWalletCardsUpdatedListenerInternal(listener) } Loading
packages/SystemUI/tests/src/com/android/systemui/wallet/controller/WalletContextualLocationsServiceTest.kt +44 −38 Original line number Diff line number Diff line Loading @@ -12,12 +12,9 @@ import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before Loading @@ -41,7 +38,8 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private lateinit var underTest: WalletContextualLocationsService private lateinit var testScope: TestScope private var listenerRegisteredCount: Int = 0 private val listener: IWalletCardsUpdatedListener.Stub = object : IWalletCardsUpdatedListener.Stub() { private val listener: IWalletCardsUpdatedListener.Stub = object : IWalletCardsUpdatedListener.Stub() { override fun registerNewWalletCards(cards: List<WalletCard?>) { listenerRegisteredCount++ } Loading @@ -60,26 +58,30 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { featureFlags.set(Flags.ENABLE_WALLET_CONTEXTUAL_LOYALTY_CARDS, true) listenerRegisteredCount = 0 underTest = WalletContextualLocationsService(controller, featureFlags, testScope.backgroundScope) underTest = WalletContextualLocationsService(controller, featureFlags, testScope.backgroundScope) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun addListener() = testScope.runTest { fun addListener() = testScope.runTest { underTest.addWalletCardsUpdatedListenerInternal(listener) assertThat(listenerRegisteredCount).isEqualTo(1) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun addStoreLocations() = testScope.runTest { fun addStoreLocations() = testScope.runTest { underTest.onWalletContextualLocationsStateUpdatedInternal(ArrayList<String>()) verify(controller, times(1)).setSuggestionCardIds(anySet()) } @Test @kotlinx.coroutines.ExperimentalCoroutinesApi fun updateListenerAndLocationsState() = testScope.runTest { fun updateListenerAndLocationsState() = testScope.runTest { // binds to the service and adds a listener val underTestStub = getInterface underTestStub.addWalletCardsUpdatedListener(listener) Loading @@ -102,8 +104,10 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private val fakeWalletCards: MutableStateFlow<List<WalletCard>> get() { val intent = Intent(getContext(), WalletContextualLocationsService::class.java) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val walletCards: ArrayList<WalletCard> = ArrayList<WalletCard>() walletCards.add(WalletCard.Builder("card1", icon, "card", pi).build()) walletCards.add(WalletCard.Builder("card2", icon, "card", pi).build()) Loading @@ -113,8 +117,10 @@ class WalletContextualLocationsServiceTest : SysuiTestCase() { private val updatedFakeWalletCards: List<WalletCard> get() { val intent = Intent(getContext(), WalletContextualLocationsService::class.java) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val pi: PendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_IMMUTABLE) val icon: Icon = Icon.createWithBitmap(Bitmap.createBitmap(70, 50, Bitmap.Config.ARGB_8888)) val walletCards: ArrayList<WalletCard> = ArrayList<WalletCard>() walletCards.add(WalletCard.Builder("card3", icon, "card", pi).build()) return walletCards Loading