1 /* 2 * Copyright (C) 2023 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 com.android.settings.core.BasePreferenceController.AVAILABLE; 20 import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE; 21 22 import static org.junit.Assert.assertEquals; 23 24 import android.content.Context; 25 import android.os.LocaleList; 26 import android.platform.test.annotations.DisableFlags; 27 import android.platform.test.flag.junit.SetFlagsRule; 28 29 import androidx.test.core.app.ApplicationProvider; 30 31 import com.android.settings.flags.Flags; 32 33 import org.junit.Before; 34 import org.junit.Rule; 35 import org.junit.Test; 36 37 public class NumberingSystemControllerTest { 38 private Context mApplicationContext; 39 private NumberingSystemController mController; 40 41 @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 42 43 @Before setUp()44 public void setUp() throws Exception { 45 mApplicationContext = ApplicationProvider.getApplicationContext(); 46 } 47 48 @Test 49 @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) getAvailabilityStatus_noLocale_unavailable()50 public void getAvailabilityStatus_noLocale_unavailable() { 51 LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW")); 52 mController = new NumberingSystemController(mApplicationContext, "key"); 53 54 int result = mController.getAvailabilityStatus(); 55 56 assertEquals(CONDITIONALLY_UNAVAILABLE, result); 57 } 58 59 @Test 60 @DisableFlags(Flags.FLAG_REGIONAL_PREFERENCES_API_ENABLED) getAvailabilityStatus_hasLocaleWithNumberingSystems_available()61 public void getAvailabilityStatus_hasLocaleWithNumberingSystems_available() { 62 // ar-JO has different numbering system. 63 LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-Hant-TW,ar-JO")); 64 mController = new NumberingSystemController(mApplicationContext, "key"); 65 66 int result = mController.getAvailabilityStatus(); 67 68 assertEquals(AVAILABLE, result); 69 } 70 } 71