1 /* 2 * Copyright (C) 2022 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.settings.bluetooth; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.bluetooth.BluetoothLeBroadcastMetadata; 22 import android.bluetooth.BluetoothLeBroadcastReceiveState; 23 import android.content.Context; 24 25 import androidx.test.core.app.ApplicationProvider; 26 27 import org.junit.Before; 28 import org.junit.Rule; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.Mock; 32 import org.mockito.Spy; 33 import org.mockito.junit.MockitoJUnit; 34 import org.mockito.junit.MockitoRule; 35 import org.robolectric.RobolectricTestRunner; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class BluetoothBroadcastSourcePreferenceTest { 39 40 @Rule 41 public final MockitoRule mMockitoRule = MockitoJUnit.rule(); 42 @Spy 43 Context mContext = ApplicationProvider.getApplicationContext(); 44 @Mock 45 BluetoothLeBroadcastReceiveState mBroadcastReceiveState; 46 @Mock 47 BluetoothLeBroadcastMetadata mBroadcastMetadata; 48 49 BluetoothBroadcastSourcePreference mPreference; 50 51 52 @Before setUp()53 public void setUp() { 54 mPreference = new BluetoothBroadcastSourcePreference(mContext); 55 } 56 57 @Test isCreatedByReceiveState_updateUiFromReceviceState_returnsTrue()58 public void isCreatedByReceiveState_updateUiFromReceviceState_returnsTrue() { 59 mPreference.updateReceiveStateAndRefreshUi(mBroadcastReceiveState); 60 61 assertThat(mPreference.isCreatedByReceiveState()).isTrue(); 62 } 63 64 @Test isCreatedByReceiveState_updateUiFromMetadata_returnsFalse()65 public void isCreatedByReceiveState_updateUiFromMetadata_returnsFalse() { 66 mPreference.updateMetadataAndRefreshUi(mBroadcastMetadata, true); 67 68 assertThat(mPreference.isCreatedByReceiveState()).isFalse(); 69 } 70 71 } 72