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.suggestions; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.annotation.StringRes; 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.content.pm.ActivityInfo; 25 import android.content.pm.PackageManager; 26 import android.content.pm.PackageManager.NameNotFoundException; 27 28 import com.android.settings.R; 29 import com.android.settings.Settings; 30 import com.android.settings.biometrics.fingerprint.FingerprintEnrollSuggestionActivity; 31 import com.android.settings.biometrics.fingerprint.FingerprintSuggestionActivity; 32 import com.android.settings.notification.zen.ZenSuggestionActivity; 33 import com.android.settings.wallpaper.WallpaperSuggestionActivity; 34 import com.android.settings.wifi.calling.WifiCallingSuggestionActivity; 35 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.robolectric.RobolectricTestRunner; 39 import org.robolectric.RuntimeEnvironment; 40 41 @RunWith(RobolectricTestRunner.class) 42 public class SettingsSuggestionsTest { 43 44 @Test wallpaperSuggestion_isValid()45 public void wallpaperSuggestion_isValid() { 46 assertSuggestionEquals( 47 WallpaperSuggestionActivity.class.getName(), 48 R.string.wallpaper_suggestion_title, 49 R.string.wallpaper_suggestion_summary); 50 } 51 52 @Test fingerprintSuggestion_isValid()53 public void fingerprintSuggestion_isValid() { 54 assertSuggestionEquals( 55 FingerprintSuggestionActivity.class.getName(), 56 R.string.suggestion_additional_fingerprints, 57 R.string.suggestion_additional_fingerprints_summary); 58 } 59 60 @Test fingerprintEnrollSuggestion_isValid()61 public void fingerprintEnrollSuggestion_isValid() { 62 assertSuggestionEquals( 63 FingerprintEnrollSuggestionActivity.class.getName(), 64 R.string.suggested_fingerprint_lock_settings_title, 65 R.string.suggested_fingerprint_lock_settings_summary); 66 } 67 68 @Test wifiCallingSuggestion_isValid()69 public void wifiCallingSuggestion_isValid() { 70 assertSuggestionEquals( 71 WifiCallingSuggestionActivity.class.getName(), 72 R.string.wifi_calling_suggestion_title, 73 R.string.wifi_calling_suggestion_summary); 74 } 75 76 @Test nightDisplaySuggestion_isValid()77 public void nightDisplaySuggestion_isValid() { 78 assertSuggestionEquals( 79 Settings.NightDisplaySuggestionActivity.class.getName(), 80 R.string.night_display_suggestion_title, 81 R.string.night_display_suggestion_summary); 82 } 83 84 @Test zenSuggestion_isValid()85 public void zenSuggestion_isValid() { 86 assertSuggestionEquals( 87 ZenSuggestionActivity.class.getName(), 88 R.string.zen_suggestion_title, 89 R.string.zen_suggestion_summary); 90 } 91 assertSuggestionEquals(String activityName, @StringRes int titleRes, @StringRes int summaryRes)92 private void assertSuggestionEquals(String activityName, @StringRes int titleRes, 93 @StringRes int summaryRes) { 94 95 final Context context = RuntimeEnvironment.application; 96 final PackageManager pm = context.getPackageManager(); 97 final ComponentName componentName = new ComponentName(context, activityName); 98 final ActivityInfo info; 99 try { 100 info = pm.getActivityInfo(componentName, PackageManager.GET_META_DATA); 101 } catch (NameNotFoundException e) { 102 throw new RuntimeException(e); 103 } 104 105 final int titleResourceId = (int) info.metaData.get("com.android.settings.title"); 106 assertThat(titleResourceId).isEqualTo(titleRes); 107 108 final int summaryResourceId = (int) info.metaData.get("com.android.settings.summary"); 109 assertThat(summaryResourceId).isEqualTo(summaryRes); 110 } 111 } 112