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.users; 18 19 import android.app.Activity; 20 import android.content.pm.UserInfo; 21 import android.os.UserManager; 22 23 import com.android.settings.R; 24 import com.android.settings.SettingsRobolectricTestRunner; 25 import com.android.settings.TestConfig; 26 import com.android.settings.dashboard.SummaryLoader; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.Mock; 32 import org.mockito.MockitoAnnotations; 33 import org.robolectric.annotation.Config; 34 import org.robolectric.Robolectric; 35 36 import static org.mockito.Matchers.anyInt; 37 import static org.mockito.Mockito.spy; 38 import static org.mockito.Mockito.verify; 39 import static org.mockito.Mockito.when; 40 41 @RunWith(SettingsRobolectricTestRunner.class) 42 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 43 public class UserSettingsTest { 44 45 @Mock private UserManager mUserManager; 46 @Mock private SummaryLoader mSummaryLoader; 47 private Activity mActivity; 48 private SummaryLoader.SummaryProvider mSummaryProvider; 49 50 @Before setUp()51 public void setUp() { 52 MockitoAnnotations.initMocks(this); 53 mActivity = spy(Robolectric.buildActivity(Activity.class).get()); 54 when((Object) mActivity.getSystemService(UserManager.class)).thenReturn(mUserManager); 55 56 mSummaryProvider = UserSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider( 57 mActivity, mSummaryLoader); 58 } 59 60 @Test setListening_shouldSetSummaryWithUserName()61 public void setListening_shouldSetSummaryWithUserName() { 62 final String name = "John"; 63 final UserInfo userInfo = new UserInfo(); 64 userInfo.name = name; 65 when(mUserManager.getUserInfo(anyInt())).thenReturn(userInfo); 66 67 mSummaryProvider.setListening(true); 68 69 verify(mSummaryLoader).setSummary(mSummaryProvider, 70 mActivity.getString(R.string.users_summary, name)); 71 } 72 73 } 74