1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.wallet.util
18 
19 import android.service.quickaccesswallet.WalletCard
20 import android.testing.TestableLooper.RunWithLooper
21 import androidx.test.ext.junit.runners.AndroidJUnit4
22 import androidx.test.filters.SmallTest
23 import com.android.systemui.SysuiTestCase
24 import com.android.systemui.util.mockito.mock
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Test
27 import org.junit.runner.RunWith
28 
29 /** Test class for WalletCardUtils */
30 @RunWith(AndroidJUnit4::class)
31 @RunWithLooper
32 @SmallTest
33 class WalletCardUtilsTest : SysuiTestCase() {
34 
35     private val paymentCard = createWalletCardWithType(WalletCard.CARD_TYPE_PAYMENT)
36     private val nonPaymentCard = createWalletCardWithType(WalletCard.CARD_TYPE_NON_PAYMENT)
37     private val unknownCard = createWalletCardWithType(WalletCard.CARD_TYPE_UNKNOWN)
38 
39     @Test
paymentCards_cardTypesAllUnknown_getsAllCardsnull40     fun paymentCards_cardTypesAllUnknown_getsAllCards() {
41         val walletCardList =
42             mutableListOf(
43                 createWalletCardWithType(WalletCard.CARD_TYPE_UNKNOWN),
44                 createWalletCardWithType(WalletCard.CARD_TYPE_UNKNOWN),
45                 createWalletCardWithType(WalletCard.CARD_TYPE_UNKNOWN)
46             )
47 
48         assertThat(walletCardList).isEqualTo(getPaymentCards(walletCardList))
49     }
50 
51     @Test
paymentCards_cardTypesDifferent_onlyGetsPaymentnull52     fun paymentCards_cardTypesDifferent_onlyGetsPayment() {
53         val walletCardList = mutableListOf(paymentCard, nonPaymentCard, unknownCard)
54 
55         assertThat(getPaymentCards(walletCardList)).isEqualTo(mutableListOf(paymentCard))
56     }
57 
createWalletCardWithTypenull58     private fun createWalletCardWithType(cardType: Int): WalletCard {
59         return WalletCard.Builder(
60                 /*cardId= */ CARD_ID,
61                 /*cardType= */ cardType,
62                 /*cardImage= */ mock(),
63                 /*contentDescription=  */ CARD_DESCRIPTION,
64                 /*pendingIntent= */ mock()
65             )
66             .build()
67     }
68 
69     companion object {
70         private const val CARD_ID: String = "ID"
71         private const val CARD_DESCRIPTION: String = "Description"
72     }
73 }
74