1/*
2 * Copyright (C) 2016 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.internal.util.test;
18
19import android.content.ContentResolver;
20import android.database.ContentObserver;
21import android.net.Uri;
22import android.provider.Settings;
23import android.test.AndroidTestCase;
24import android.test.mock.MockContentResolver;
25import android.test.mock.MockContext;
26import android.test.suitebuilder.annotation.SmallTest;
27import android.test.suitebuilder.annotation.Suppress;
28import android.util.Log;
29
30import java.util.concurrent.CountDownLatch;
31import java.util.concurrent.TimeUnit;
32
33/**
34 * Unit tests for FakeSettingsProvider.
35 */
36public class FakeSettingsProviderTest extends AndroidTestCase {
37
38    private MockContentResolver mCr;
39
40    @Override
41    public void setUp() throws Exception {
42        mCr = new MockContentResolver();
43        mCr.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
44    }
45
46    @SmallTest
47    public void testBasicOperation() throws Exception {
48        String settingName = Settings.System.SCREEN_BRIGHTNESS;
49
50        try {
51            Settings.System.getInt(mCr, settingName);
52            fail("FakeSettingsProvider should start off empty.");
53        } catch (Settings.SettingNotFoundException expected) {}
54
55        // Check that fake settings can be written and read back.
56        Settings.System.putInt(mCr, settingName, 123);
57        assertEquals(123, Settings.System.getInt(mCr, settingName));
58    }
59}
60