1 /* 2 * Copyright (C) 2019 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.language; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.Mockito.mock; 23 import static org.mockito.Mockito.spy; 24 import static org.mockito.Mockito.when; 25 26 import android.content.ComponentName; 27 import android.content.ContentResolver; 28 import android.content.Context; 29 import android.provider.Settings; 30 import android.view.inputmethod.InputMethodInfo; 31 32 import com.android.settings.testutils.shadow.ShadowInputMethodManagerWithMethodList; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.robolectric.RobolectricTestRunner; 38 import org.robolectric.RuntimeEnvironment; 39 import org.robolectric.annotation.Config; 40 41 import java.util.ArrayList; 42 import java.util.List; 43 44 @RunWith(RobolectricTestRunner.class) 45 @Config(shadows = ShadowInputMethodManagerWithMethodList.class) 46 public class LanguageAndInputPreferenceControllerTest { 47 private Context mContext; 48 49 @Before setUp()50 public void setUp() { 51 mContext = spy(RuntimeEnvironment.application); 52 } 53 54 @Test getSummary_shouldSetToCurrentImeName()55 public void getSummary_shouldSetToCurrentImeName() { 56 final ComponentName componentName = new ComponentName("name1", "cls"); 57 final ContentResolver cr = mContext.getContentResolver(); 58 Settings.Secure.putString(cr, Settings.Secure.DEFAULT_INPUT_METHOD, 59 componentName.flattenToString()); 60 final List<InputMethodInfo> imis = new ArrayList<>(); 61 imis.add(mock(InputMethodInfo.class)); 62 when(imis.get(0).getPackageName()).thenReturn("name1"); 63 when(imis.get(0).loadLabel(any())).thenReturn("label"); 64 ShadowInputMethodManagerWithMethodList.getShadow().setInputMethodList(imis); 65 66 final LanguageAndInputPreferenceController controller = 67 new LanguageAndInputPreferenceController(mContext, "key"); 68 69 assertThat(controller.getSummary().toString()).contains("label"); 70 } 71 } 72