• 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.accessibility;
18 
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.spy;
21 import static org.mockito.Mockito.verify;
22 
23 import android.os.Bundle;
24 import android.support.annotation.XmlRes;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 
29 import com.android.settings.R;
30 import com.android.settings.testutils.SettingsRobolectricTestRunner;
31 import com.android.settings.testutils.shadow.SettingsShadowResources;
32 import com.android.settings.widget.SwitchBar;
33 
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.robolectric.annotation.Config;
37 import org.robolectric.util.FragmentTestUtil;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 @Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
41 public class ToggleFeaturePreferenceFragmentTest {
42 
43     private ToggleFeaturePreferenceFragmentTestable mFragment;
44 
45     @Test
createFragment_shouldOnlyAddPreferencesOnce()46     public void createFragment_shouldOnlyAddPreferencesOnce() {
47         mFragment = spy(new ToggleFeaturePreferenceFragmentTestable());
48         FragmentTestUtil.startFragment(mFragment);
49 
50         // execute exactly once
51         verify(mFragment).addPreferencesFromResource(R.xml.placeholder_prefs);
52     }
53 
54     public static class ToggleFeaturePreferenceFragmentTestable
55             extends ToggleFeaturePreferenceFragment {
56 
57         @Override
onPreferenceToggled(String preferenceKey, boolean enabled)58         protected void onPreferenceToggled(String preferenceKey, boolean enabled) {}
59 
60         @Override
getMetricsCategory()61         public int getMetricsCategory() {
62             return 0;
63         }
64 
65         @Override
getPreferenceScreenResId()66         public int getPreferenceScreenResId() {
67             return R.xml.placeholder_prefs;
68         }
69 
70         @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)71         public View onCreateView(LayoutInflater inflater, ViewGroup container,
72                 Bundle savedInstanceState) {
73             return mock(View.class);
74         }
75 
76         @Override
addPreferencesFromResource(@mlRes int preferencesResId)77         public void addPreferencesFromResource(@XmlRes int preferencesResId) {
78             // do nothing
79         }
80 
81         @Override
onViewCreated(View view, Bundle savedInstanceState)82         public void onViewCreated(View view, Bundle savedInstanceState) {
83             // do nothing
84         }
85 
86         @Override
onActivityCreated(Bundle savedInstanceState)87         public void onActivityCreated(Bundle savedInstanceState) {
88             mSwitchBar = mock(SwitchBar.class);
89             super.onActivityCreated(savedInstanceState);
90         }
91     }
92 }
93