• 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 package com.android.settings;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static org.mockito.Mockito.spy;
20 
21 import android.content.Context;
22 
23 import com.android.settings.testutils.SettingsRobolectricTestRunner;
24 import com.android.settings.testutils.XmlTestUtils;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.MockitoAnnotations;
30 import org.robolectric.RuntimeEnvironment;
31 import org.robolectric.annotation.Config;
32 
33 import java.util.List;
34 
35 @RunWith(SettingsRobolectricTestRunner.class)
36 public class LegalSettingsTest {
37 
38     private Context mContext;
39     private LegalSettings mFragment;
40     private boolean mWallpaperRemoved;
41 
42     @Before
setUp()43     public void setUp() {
44         MockitoAnnotations.initMocks(this);
45         mContext = spy(RuntimeEnvironment.application);
46         mFragment = new LegalSettings() {
47             @Override
48             public boolean removePreference(String key) {
49                 if (LegalSettings.KEY_WALLPAPER_ATTRIBUTIONS.equals(key)) {
50                     mWallpaperRemoved = true;
51 
52                     return true;
53                 }
54                 return false;
55             }
56         };
57     }
58 
59     @Test
testNonIndexableKeys_existInXmlLayout()60     public void testNonIndexableKeys_existInXmlLayout() {
61         final Context context = RuntimeEnvironment.application;
62         final List<String> niks =
63             LegalSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(context);
64 
65         final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.about_legal);
66 
67         assertThat(keys).containsAllIn(niks);
68     }
69 
70     @Test
testWallpaperAttributions_byDefault_shouldBeShown()71     public void testWallpaperAttributions_byDefault_shouldBeShown() {
72         mFragment.checkWallpaperAttributionAvailability(mContext);
73 
74         assertThat(mWallpaperRemoved).isEqualTo(false);
75     }
76 
77     @Test
78     @Config(qualifiers = "mcc999")
testWallpaperAttributions_ifDisabled_shouldNotBeShown()79     public void testWallpaperAttributions_ifDisabled_shouldNotBeShown() {
80         mFragment.checkWallpaperAttributionAvailability(mContext);
81 
82         assertThat(mWallpaperRemoved).isEqualTo(true);
83     }
84 }
85