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.security.screenlock; 18 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.mockito.Mockito.mock; 21 import static org.mockito.Mockito.verify; 22 23 import com.android.internal.logging.nano.MetricsProto; 24 import com.android.settings.R; 25 import com.android.settings.security.OwnerInfoPreferenceController; 26 import com.android.settings.testutils.SettingsRobolectricTestRunner; 27 import com.android.settingslib.core.AbstractPreferenceController; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.robolectric.util.ReflectionHelpers; 33 34 import java.util.ArrayList; 35 import java.util.List; 36 import java.util.Map; 37 38 @RunWith(SettingsRobolectricTestRunner.class) 39 public class ScreenLockSettingsTest { 40 41 private ScreenLockSettings mSettings; 42 43 @Before 44 public void setUp() { 45 mSettings = new ScreenLockSettings(); 46 } 47 48 @Test 49 public void verifyConstants() { 50 assertThat(mSettings.getMetricsCategory()) 51 .isEqualTo(MetricsProto.MetricsEvent.SCREEN_LOCK_SETTINGS); 52 assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.screen_lock_settings); 53 } 54 55 @Test 56 public void onOwnerInfoUpdated_shouldUpdateOwnerInfoController() { 57 final Map<Class, List<AbstractPreferenceController>> preferenceControllers = 58 ReflectionHelpers.getField(mSettings, "mPreferenceControllers"); 59 final OwnerInfoPreferenceController controller = mock(OwnerInfoPreferenceController.class); 60 List<AbstractPreferenceController> controllerList = new ArrayList<>(); 61 controllerList.add(controller); 62 preferenceControllers.put(OwnerInfoPreferenceController.class, controllerList); 63 64 mSettings.onOwnerInfoUpdated(); 65 66 verify(controller).updateSummary(); 67 } 68 } 69