blob: d19d19ab62e93be27dbb9eaefaeb39921bbd3dfb [file] [log] [blame]
Tony Mantler4ca9ebd2017-07-31 10:54:20 -07001/*
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
17package com.android.settingslib.development;
18
19import static com.google.common.truth.Truth.assertThat;
20
21import android.content.Context;
22import android.provider.Settings;
23
24import com.android.settingslib.SettingsLibRobolectricTestRunner;
25import com.android.settingslib.TestConfig;
26
27import org.junit.Before;
28import org.junit.Test;
29import org.junit.runner.RunWith;
30import org.robolectric.RuntimeEnvironment;
31import org.robolectric.annotation.Config;
32
33@RunWith(SettingsLibRobolectricTestRunner.class)
34@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
35public class DevelopmentSettingsEnablerTest {
36
37 private Context mContext;
38
39 @Before
40 public void setUp() {
41 mContext = RuntimeEnvironment.application;
42 }
43
44 @Test
45 public void testEnabling() {
46 Settings.Global.putInt(mContext.getContentResolver(),
47 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
48
49 assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
50
51 DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mContext, true);
52
53 assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isTrue();
54 }
55
56 @Test
57 public void testDisabling() {
58 Settings.Global.putInt(mContext.getContentResolver(),
59 Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 1);
60
61 assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isTrue();
62
63 DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mContext, false);
64
65 assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isFalse();
66 }
67}