Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c12971c authored by Hyundo Moon's avatar Hyundo Moon Committed by Automerger Merge Worker
Browse files

Merge "Add BluetoothPbapConfigTest" am: 0eae4a48 am: 21cbb8a1 am:...

Merge "Add BluetoothPbapConfigTest" am: 0eae4a48 am: 21cbb8a1 am: 1f041d36 am: 361b7c59 am: 65592c67

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2147709



Change-Id: Ia19f48ffd83c36b1f1eef6f4929443a2de2a8d05
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 929f8892 65592c67
Loading
Loading
Loading
Loading
+106 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.bluetooth.pbap;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.res.Resources;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.R;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class BluetoothPbapConfigTest {

    @Mock
    Context mContext;

    @Mock
    Resources mResources;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        when(mContext.getResources()).thenReturn(mResources);
    }

    @Test
    public void testInit_whenUseProfileForOwnerVcardIsTrue() {
        when(mResources.getBoolean(R.bool.pbap_use_profile_for_owner_vcard))
                .thenReturn(true);

        BluetoothPbapConfig.init(mContext);
        assertThat(BluetoothPbapConfig.useProfileForOwnerVcard()).isTrue();
    }

    @Test
    public void testInit_whenUseProfileForOwnerVcardIsFalse() {
        when(mResources.getBoolean(R.bool.pbap_use_profile_for_owner_vcard))
                .thenReturn(false);

        BluetoothPbapConfig.init(mContext);
        assertThat(BluetoothPbapConfig.useProfileForOwnerVcard()).isFalse();
    }

    @Test
    public void testInit_whenUseProfileForOwnerVcardThrowsException() {
        when(mResources.getBoolean(R.bool.pbap_use_profile_for_owner_vcard))
                .thenThrow(new RuntimeException());

        BluetoothPbapConfig.init(mContext);
        // Test should not crash
    }

    @Test
    public void testInit_whenIncludePhotosInVcardIsTrue() {
        when(mResources.getBoolean(R.bool.pbap_include_photos_in_vcard))
                .thenReturn(true);

        BluetoothPbapConfig.init(mContext);
        assertThat(BluetoothPbapConfig.includePhotosInVcard()).isTrue();
    }

    @Test
    public void testInit_whenIncludePhotosInVcardIsFalse() {
        when(mResources.getBoolean(R.bool.pbap_include_photos_in_vcard))
                .thenReturn(false);

        BluetoothPbapConfig.init(mContext);
        assertThat(BluetoothPbapConfig.includePhotosInVcard()).isFalse();
    }

    @Test
    public void testInit_whenIncludePhotosInVcardThrowsException() {
        when(mResources.getBoolean(R.bool.pbap_include_photos_in_vcard))
                .thenThrow(new RuntimeException());

        BluetoothPbapConfig.init(mContext);
        // Test should not crash
    }
}
 No newline at end of file