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.localepicker; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.spy; 22 23 import android.app.GrammaticalInflectionManager; 24 import android.content.Context; 25 import android.content.res.Configuration; 26 import android.os.Looper; 27 28 import androidx.preference.PreferenceCategory; 29 import androidx.preference.PreferenceManager; 30 import androidx.preference.PreferenceScreen; 31 import androidx.test.core.app.ApplicationProvider; 32 import androidx.test.ext.junit.runners.AndroidJUnit4; 33 34 import com.android.settings.widget.TickButtonPreference; 35 36 import org.junit.Before; 37 import org.junit.Ignore; 38 import org.junit.Test; 39 import org.junit.runner.RunWith; 40 import org.mockito.MockitoAnnotations; 41 42 @RunWith(AndroidJUnit4.class) 43 public class TermsOfAddressMasculineControllerTest { 44 45 private static final String KEY_CATEGORY_TERMS_OF_ADDRESS = "key_category_terms_of_address"; 46 private static final String KEY_FEMININE = "key_terms_of_address_feminine"; 47 private static final String KEY_MASCULINE = "key_terms_of_address_masculine"; 48 private static final String KEY_NEUTRAL = "key_terms_of_address_neutral"; 49 private static final String KEY_NOT_SPECIFIED = "key_terms_of_address_not_specified"; 50 51 private Context mContext; 52 private PreferenceManager mPreferenceManager; 53 private PreferenceCategory mPreferenceCategory; 54 private PreferenceScreen mPreferenceScreen; 55 private TermsOfAddressMasculineController mController; 56 private TickButtonPreference mFemininePreference; 57 private TickButtonPreference mMasculinePreference; 58 private TickButtonPreference mNotSpecifiedPreference; 59 private TickButtonPreference mNeutralPreference; 60 private GrammaticalInflectionManager mGrammaticalInflectionManager; 61 62 @Before setUp()63 public void setUp() throws Exception { 64 MockitoAnnotations.initMocks(this); 65 mContext = spy(ApplicationProvider.getApplicationContext()); 66 67 if (Looper.myLooper() == null) { 68 Looper.prepare(); 69 } 70 71 mGrammaticalInflectionManager = mContext.getSystemService( 72 GrammaticalInflectionManager.class); 73 mPreferenceManager = new PreferenceManager(mContext); 74 mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext); 75 mPreferenceCategory = new PreferenceCategory(mContext); 76 mPreferenceCategory.setKey(KEY_CATEGORY_TERMS_OF_ADDRESS); 77 mNotSpecifiedPreference = new TickButtonPreference(mContext); 78 mNotSpecifiedPreference.setKey(KEY_NOT_SPECIFIED); 79 mFemininePreference = new TickButtonPreference(mContext); 80 mFemininePreference.setKey(KEY_FEMININE); 81 mMasculinePreference = new TickButtonPreference(mContext); 82 mMasculinePreference.setKey(KEY_MASCULINE); 83 mNeutralPreference = new TickButtonPreference(mContext); 84 mNeutralPreference.setKey(KEY_NEUTRAL); 85 mPreferenceScreen.addPreference(mPreferenceCategory); 86 mPreferenceScreen.addPreference(mNotSpecifiedPreference); 87 mPreferenceScreen.addPreference(mFemininePreference); 88 mPreferenceScreen.addPreference(mMasculinePreference); 89 mPreferenceScreen.addPreference(mNeutralPreference); 90 mController = new TermsOfAddressMasculineController(mContext, KEY_MASCULINE); 91 mController.setTermsOfAddressHelper(new TermsOfAddressHelper(mContext)); 92 mController.displayPreference(mPreferenceScreen); 93 } 94 95 @Test 96 @Ignore("b/339543490") displayPreference_setGrammaticalGenderIsMasculine_MasculineIsSelected()97 public void displayPreference_setGrammaticalGenderIsMasculine_MasculineIsSelected() { 98 TickButtonPreference selectedPreference = 99 (TickButtonPreference) mPreferenceScreen.getPreference(3); 100 selectedPreference.performClick(); 101 102 assertThat(selectedPreference.getKey()).isEqualTo(KEY_MASCULINE); 103 assertThat(mGrammaticalInflectionManager.getSystemGrammaticalGender()).isEqualTo( 104 Configuration.GRAMMATICAL_GENDER_MASCULINE); 105 } 106 } 107