Home | History | Annotate | Download | only in bluetooth
      1 /*
      2  * Copyright (C) 2016 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 android.content.Context;
     20 
     21 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     22 import com.android.settings.TestConfig;
     23 import com.android.settings.dashboard.SummaryLoader;
     24 import com.android.settingslib.bluetooth.LocalBluetoothManager;
     25 
     26 import org.junit.Before;
     27 import org.junit.Test;
     28 import org.junit.runner.RunWith;
     29 import org.mockito.Answers;
     30 import org.mockito.Mock;
     31 import org.mockito.MockitoAnnotations;
     32 import org.robolectric.RuntimeEnvironment;
     33 import org.robolectric.annotation.Config;
     34 
     35 import static org.mockito.Mockito.verify;
     36 
     37 @RunWith(SettingsRobolectricTestRunner.class)
     38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
     39 public class BluetoothSettingsSummaryProviderTest {
     40 
     41     private Context mContext;
     42     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
     43     private LocalBluetoothManager mBluetoothManager;
     44     @Mock
     45     private SummaryLoader mSummaryLoader;
     46 
     47     private BluetoothSettings.SummaryProvider mSummaryProvider;
     48 
     49     @Before
     50     public void setUp() {
     51         MockitoAnnotations.initMocks(this);
     52         mContext = RuntimeEnvironment.application.getApplicationContext();
     53         mSummaryProvider = new BluetoothSettings.SummaryProvider(mContext, mSummaryLoader,
     54                 mBluetoothManager);
     55     }
     56 
     57     @Test
     58     public void setListening_shouldRegister() {
     59         mSummaryProvider.setListening(true);
     60 
     61         verify(mBluetoothManager.getEventManager()).registerCallback(
     62             mSummaryProvider.mSummaryUpdater);
     63     }
     64 
     65     @Test
     66     public void setNotListening_shouldUnregister() {
     67         mSummaryProvider.setListening(false);
     68 
     69         verify(mBluetoothManager.getEventManager()).unregisterCallback(
     70             mSummaryProvider.mSummaryUpdater);
     71     }
     72 
     73     @Test
     74     public void onSummaryChanged_shouldSetSummary() {
     75         final String summary = "Bluetooth summary";
     76         mSummaryProvider.onSummaryChanged(summary);
     77 
     78         verify(mSummaryLoader).setSummary(mSummaryProvider, summary);
     79     }
     80 
     81 }
     82