• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Matchers.anyInt;
21 import static org.mockito.Mockito.spy;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 
25 import android.app.Activity;
26 import android.content.pm.UserInfo;
27 import android.os.UserManager;
28 
29 import com.android.settings.R;
30 import com.android.settings.dashboard.SummaryLoader;
31 import com.android.settings.testutils.SettingsRobolectricTestRunner;
32 
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.robolectric.Robolectric;
39 
40 @RunWith(SettingsRobolectricTestRunner.class)
41 public class UserSettingsTest {
42 
43     @Mock
44     private UserManager mUserManager;
45     @Mock
46     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 =
57             UserSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(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)
70             .setSummary(mSummaryProvider, mActivity.getString(R.string.users_summary, name));
71     }
72 
73     @Test
testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash()74     public void testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash() {
75         // Should not crash here
76         assertThat(UserSettings.assignDefaultPhoto(null, 0)).isFalse();
77     }
78 }
79