• 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.support.actionbar;
18 
19 import static org.mockito.Mockito.doReturn;
20 import static org.mockito.Mockito.spy;
21 import static org.mockito.Mockito.verify;
22 
23 import android.content.Context;
24 import android.os.Bundle;
25 
26 import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.robolectric.RobolectricTestRunner;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class HelpMenuControllerTest {
37 
38     @Mock
39     private Context mContext;
40     private TestFragment mHost;
41 
42     @Before
setUp()43     public void setUp() {
44         MockitoAnnotations.initMocks(this);
45         mHost = spy(new TestFragment());
46         doReturn(mContext).when(mHost).getContext();
47     }
48 
49     @Test
onCreateOptionsMenu_withArgumentOverride_shouldPrepareHelpUsingOverride()50     public void onCreateOptionsMenu_withArgumentOverride_shouldPrepareHelpUsingOverride() {
51         final Bundle bundle = new Bundle();
52         bundle.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 123);
53         mHost.setArguments(bundle);
54 
55         HelpMenuController.init(mHost);
56 
57         mHost.getSettingsLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
58 
59         verify(mContext).getString(123);
60     }
61 
62     @Test
onCreateOptionsMenu_noArgumentOverride_shouldPrepareHelpUsingProvider()63     public void onCreateOptionsMenu_noArgumentOverride_shouldPrepareHelpUsingProvider() {
64         HelpMenuController.init(mHost);
65 
66         mHost.getSettingsLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
67 
68         verify(mContext).getString(mHost.getHelpResource());
69     }
70 
71     private static class TestFragment extends ObservablePreferenceFragment
72         implements HelpResourceProvider {
73 
74         @Override
onCreatePreferences(Bundle savedInstanceState, String rootKey)75         public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
76         }
77     }
78 }
79