• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings.bluetooth;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.support.v7.preference.Preference;
25 import android.text.TextUtils;
26 
27 import com.android.settings.testutils.SettingsRobolectricTestRunner;
28 import com.android.settings.TestConfig;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.RuntimeEnvironment;
35 import org.robolectric.annotation.Config;
36 import org.robolectric.shadows.ShadowApplication;
37 
38 import java.util.List;
39 
40 @RunWith(SettingsRobolectricTestRunner.class)
41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
42 public class BluetoothFilesPreferenceControllerTest {
43     private Context mContext;
44     private BluetoothFilesPreferenceController mController;
45     private Preference mPreference;
46 
47     @Before
setUp()48     public void setUp() {
49         MockitoAnnotations.initMocks(this);
50 
51         mContext = RuntimeEnvironment.application;
52         mController = new BluetoothFilesPreferenceController(mContext);
53         mPreference = new Preference(mContext);
54         mPreference.setKey(BluetoothFilesPreferenceController.KEY_RECEIVED_FILES);
55     }
56 
57     @Test
testHandlePreferenceTreeClick_sendBroadcast()58     public void testHandlePreferenceTreeClick_sendBroadcast() {
59         mController.handlePreferenceTreeClick(mPreference);
60 
61         final Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
62         assertThat(intent).isNotNull();
63         assertThat(intent.getAction()).isEqualTo(
64                 BluetoothFilesPreferenceController.ACTION_OPEN_FILES);
65 
66         final Bundle bundle = intent.getExtras();
67         assertThat(bundle.getInt(BluetoothFilesPreferenceController.EXTRA_DIRECTION)).isEqualTo(1);
68         assertThat(bundle.getBoolean(
69                 BluetoothFilesPreferenceController.EXTRA_SHOW_ALL_FILES)).isTrue();
70     }
71 }
72