Home | History | Annotate | Download | only in test
      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 
     17 package com.android.internal.util.test;
     18 
     19 import android.content.ContentResolver;
     20 import android.database.ContentObserver;
     21 import android.net.Uri;
     22 import android.provider.Settings;
     23 import android.test.AndroidTestCase;
     24 import android.test.mock.MockContentResolver;
     25 import android.test.mock.MockContext;
     26 import android.test.suitebuilder.annotation.SmallTest;
     27 import android.test.suitebuilder.annotation.Suppress;
     28 import android.util.Log;
     29 
     30 import java.util.concurrent.CountDownLatch;
     31 import java.util.concurrent.TimeUnit;
     32 
     33 /**
     34  * Unit tests for FakeSettingsProvider.
     35  */
     36 public 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