• 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.enterprise;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.when;
21 
22 import android.content.Context;
23 import android.support.v7.preference.Preference;
24 
25 import com.android.settings.testutils.FakeFeatureFactory;
26 import com.android.settings.testutils.SettingsRobolectricTestRunner;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Answers;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 
35 @RunWith(SettingsRobolectricTestRunner.class)
36 public class GlobalHttpProxyPreferenceControllerTest {
37 
38     private static final String KEY_GLOBAL_HTTP_PROXY = "global_http_proxy";
39 
40     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
41     private Context mContext;
42     private FakeFeatureFactory mFeatureFactory;
43 
44     private GlobalHttpProxyPreferenceController mController;
45 
46     @Before
setUp()47     public void setUp() {
48         MockitoAnnotations.initMocks(this);
49         mFeatureFactory = FakeFeatureFactory.setupForTest();
50         mController = new GlobalHttpProxyPreferenceController(mContext);
51     }
52 
53     @Test
testIsAvailable()54     public void testIsAvailable() {
55         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
56                 .thenReturn(false);
57         assertThat(mController.isAvailable()).isFalse();
58 
59         when(mFeatureFactory.enterprisePrivacyFeatureProvider.isGlobalHttpProxySet())
60                 .thenReturn(true);
61         assertThat(mController.isAvailable()).isTrue();
62     }
63 
64     @Test
testHandlePreferenceTreeClick()65     public void testHandlePreferenceTreeClick() {
66         assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
67                 .isFalse();
68     }
69 
70     @Test
testGetPreferenceKey()71     public void testGetPreferenceKey() {
72         assertThat(mController.getPreferenceKey()).isEqualTo(KEY_GLOBAL_HTTP_PROXY);
73     }
74 }
75