[Catalyst] Fully migrate BluetoothMainSwitchPreference

Bug: 372774767
Flag: com.android.settings.flags.catalyst_bluetooth_switchbar_screen
Test: atest
Change-Id: Ie7a78a0ef2a8739d30ece4c1c4fde5651876dc8a
This commit is contained in:
Jacky Wang
2024-12-09 07:47:42 +08:00
parent 95719f21b3
commit 2b21d69c0c
3 changed files with 183 additions and 110 deletions

View File

@@ -31,45 +31,42 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
@RunWith(AndroidJUnit4::class)
class BluetoothMainSwitchPreferenceTest {
class BluetoothPreferenceTest {
@get:Rule val setFlagsRule = SetFlagsRule()
private val context: Context = ApplicationProvider.getApplicationContext()
private lateinit var bluetoothAdapter: BluetoothAdapter
private lateinit var bluetoothMainSwitchPreference: BluetoothMainSwitchPreference
private lateinit var bluetoothPreference: BluetoothPreference
@Before
fun setUp() {
bluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter())
whenever(bluetoothAdapter.state).thenReturn(BluetoothAdapter.STATE_ON)
bluetoothMainSwitchPreference = BluetoothMainSwitchPreference(bluetoothAdapter)
bluetoothPreference =
BluetoothPreference(BluetoothPreference.createDataStore(context, bluetoothAdapter))
}
@Test
fun isEnabled_bluetoothOn_returnTrue() {
assertThat(bluetoothMainSwitchPreference.isEnabled(context)).isTrue()
assertThat(bluetoothPreference.isEnabled(context)).isTrue()
}
@Test
fun isEnabled_bluetoothTurningOn_returnFalse() {
whenever(bluetoothAdapter.state).thenReturn(BluetoothAdapter.STATE_TURNING_ON)
assertThat(bluetoothMainSwitchPreference.isEnabled(context)).isFalse()
assertThat(bluetoothPreference.isEnabled(context)).isFalse()
}
@Test
fun storageSetOff_turnOff() {
bluetoothMainSwitchPreference
.storage(context)
.setBoolean(bluetoothMainSwitchPreference.key, false)
bluetoothPreference.storage(context).setBoolean(bluetoothPreference.key, false)
verify(bluetoothAdapter).disable()
}
@Test
fun storageSetOn_turnOn() {
bluetoothMainSwitchPreference
.storage(context)
.setBoolean(bluetoothMainSwitchPreference.key, true)
bluetoothPreference.storage(context).setBoolean(bluetoothPreference.key, true)
verify(bluetoothAdapter).enable()
}