Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2017 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 package com.android.settings.bluetooth;
     17 
     18 import android.content.Context;
     19 
     20 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     21 import com.android.settings.SettingsRobolectricTestRunner;
     22 import com.android.settings.TestConfig;
     23 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
     24 import com.android.settings.testutils.FakeFeatureFactory;
     25 import com.android.settingslib.bluetooth.LocalBluetoothManager;
     26 
     27 import org.junit.Before;
     28 import org.junit.Test;
     29 import org.junit.runner.RunWith;
     30 import org.mockito.Answers;
     31 import org.mockito.Mock;
     32 import org.mockito.MockitoAnnotations;
     33 import org.robolectric.annotation.Config;
     34 
     35 import static org.mockito.Matchers.anyInt;
     36 import static org.mockito.Matchers.anyString;
     37 import static org.mockito.Matchers.eq;
     38 import static org.mockito.Mockito.mock;
     39 import static org.mockito.Mockito.verify;
     40 import static org.mockito.Mockito.when;
     41 
     42 @RunWith(SettingsRobolectricTestRunner.class)
     43 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     44 public class UtilsTest {
     45 
     46     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     47     private Context mContext;
     48     @Mock
     49     private LocalBluetoothManager mLocalBluetoothManager;
     50 
     51     private FakeFeatureFactory mFakeFeatureFactory;
     52     private MetricsFeatureProvider mMetricsFeatureProvider;
     53 
     54     @Before
     55     public void setUp() {
     56         MockitoAnnotations.initMocks(this);
     57         FakeFeatureFactory.setupForTest(mContext);
     58         mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
     59         mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
     60     }
     61 
     62     @Test
     63     public void showConnectingError_shouldLogBluetoothConnectError() {
     64         when(mContext.getString(anyInt(), anyString())).thenReturn("testMessage");
     65         Utils.showConnectingError(mContext, "testName", mock(LocalBluetoothManager.class));
     66 
     67         verify(mMetricsFeatureProvider).visible(eq(mContext), anyInt(),
     68             eq(MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT_ERROR));
     69     }
     70 }
     71