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.statusbar.pipeline.ethernet.domain 18 19 import androidx.test.ext.junit.runners.AndroidJUnit4 20 import androidx.test.filters.SmallTest 21 import com.android.settingslib.AccessibilityContentDescriptions 22 import com.android.systemui.res.R 23 import com.android.systemui.SysuiTestCase 24 import com.android.systemui.common.shared.model.ContentDescription 25 import com.android.systemui.common.shared.model.Icon 26 import com.android.systemui.coroutines.collectLastValue 27 import com.android.systemui.statusbar.pipeline.shared.data.repository.FakeConnectivityRepository 28 import com.google.common.truth.Truth.assertThat 29 import kotlinx.coroutines.test.TestScope 30 import kotlinx.coroutines.test.runTest 31 import org.junit.Test 32 import org.junit.runner.RunWith 33 34 @SmallTest 35 @RunWith(AndroidJUnit4::class) 36 class EthernetInteractorTest : SysuiTestCase() { 37 private val connectivityRepository = FakeConnectivityRepository() 38 private val underTest = EthernetInteractor(connectivityRepository) 39 40 private val testScope = TestScope() 41 42 @Test icon_default_validatednull43 fun icon_default_validated() = 44 testScope.runTest { 45 val latest by collectLastValue(underTest.icon) 46 47 connectivityRepository.setEthernetConnected(default = true, validated = true) 48 49 val expected = 50 Icon.Resource( 51 R.drawable.stat_sys_ethernet_fully, 52 ContentDescription.Resource( 53 AccessibilityContentDescriptions.ETHERNET_CONNECTION_VALUES[1] 54 ) 55 ) 56 57 assertThat(latest).isEqualTo(expected) 58 } 59 60 @Test icon_default_notValidatednull61 fun icon_default_notValidated() = 62 testScope.runTest { 63 val latest by collectLastValue(underTest.icon) 64 65 connectivityRepository.setEthernetConnected(default = true, validated = false) 66 67 val expected = 68 Icon.Resource( 69 R.drawable.stat_sys_ethernet, 70 ContentDescription.Resource( 71 AccessibilityContentDescriptions.ETHERNET_CONNECTION_VALUES[0] 72 ) 73 ) 74 75 assertThat(latest).isEqualTo(expected) 76 } 77 78 @Test icon_notDefault_validatednull79 fun icon_notDefault_validated() = 80 testScope.runTest { 81 val latest by collectLastValue(underTest.icon) 82 83 connectivityRepository.setEthernetConnected(default = false, validated = true) 84 85 assertThat(latest).isNull() 86 } 87 88 @Test icon_notDefault_notValidatednull89 fun icon_notDefault_notValidated() = 90 testScope.runTest { 91 val latest by collectLastValue(underTest.icon) 92 93 connectivityRepository.setEthernetConnected(default = false, validated = false) 94 95 assertThat(latest).isNull() 96 } 97 } 98