• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.regionalpreferences;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.content.Context;
22 import android.platform.test.annotations.DisableFlags;
23 import android.platform.test.flag.junit.SetFlagsRule;
24 import android.provider.Settings;
25 
26 import androidx.test.core.app.ApplicationProvider;
27 
28 import com.android.settings.flags.Flags;
29 import com.android.settings.testutils.ResourcesUtils;
30 
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 
36 import java.util.Locale;
37 
38 public class FirstDayOfWeekControllerTest {
39     private Context mApplicationContext;
40     private FirstDayOfWeekController mController;
41     private String mCacheProviderContent = "";
42     private Locale mCacheLocale;
43 
44     @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
45 
46     @Before
setUp()47     public void setUp() throws Exception {
48         mApplicationContext = ApplicationProvider.getApplicationContext();
49         mController = new FirstDayOfWeekController(mApplicationContext, "key");
50         mCacheProviderContent = Settings.System.getString(
51                 mApplicationContext.getContentResolver(), Settings.System.LOCALE_PREFERENCES);
52         mCacheLocale = Locale.getDefault(Locale.Category.FORMAT);
53     }
54 
55     @After
tearDown()56     public void tearDown() throws Exception {
57         RegionalPreferenceTestUtils.setSettingsProviderContent(
58                 mApplicationContext, mCacheProviderContent);
59         Locale.setDefault(mCacheLocale);
60     }
61 
62     @Test
63     @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED)
getSummary_hasProviderValue_resultIsWed()64     public void getSummary_hasProviderValue_resultIsWed() {
65         RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-wed");
66 
67         String summary = mController.getSummary().toString();
68 
69         assertEquals(ResourcesUtils.getResourcesString(
70                 mApplicationContext, "wednesday_first_day_of_week"), summary);
71     }
72 
73     @Test
74     @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED)
getSummary_hasProviderValue_resultIsSat()75     public void getSummary_hasProviderValue_resultIsSat() {
76         RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "und-u-fw-sat");
77 
78         String summary = mController.getSummary().toString();
79 
80         assertEquals(ResourcesUtils.getResourcesString(
81                 mApplicationContext, "saturday_first_day_of_week"), summary);
82     }
83 
84     @Test
85     @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED)
getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsSat()86     public void getSummary_noProviderValueButHasDefaultLocaleWithSubtag_resultIsSat() {
87         RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "");
88         Locale.setDefault(Locale.forLanguageTag("en-US-u-fw-sat"));
89 
90         String summary = mController.getSummary().toString();
91 
92         assertEquals(ResourcesUtils.getResourcesString(
93                 mApplicationContext, "saturday_first_day_of_week"), summary);
94     }
95 
96     @Test
97     @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED)
getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsdefault()98     public void getSummary_noProviderValueAndDefaultLocaleWithoutSubtag_resultIsdefault() {
99         RegionalPreferenceTestUtils.setSettingsProviderContent(mApplicationContext, "");
100         Locale.setDefault(Locale.forLanguageTag("en-US"));
101 
102         String summary = mController.getSummary().toString();
103 
104         assertEquals(ResourcesUtils.getResourcesString(
105                 mApplicationContext, "default_string_of_regional_preference"), summary);
106     }
107 }
108