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.password; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.app.admin.DevicePolicyManager; 22 23 import com.android.settings.testutils.SettingsRobolectricTestRunner; 24 import com.android.settings.TestConfig; 25 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.robolectric.annotation.Config; 29 30 @RunWith(SettingsRobolectricTestRunner.class) 31 @Config( 32 manifest = TestConfig.MANIFEST_PATH, 33 sdk = TestConfig.SDK_VERSION) 34 public class ScreenLockTypeTest { 35 36 @Test 37 public void fromQuality_shouldReturnLockWithAssociatedQuality() { 38 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC)) 39 .isEqualTo(ScreenLockType.PASSWORD); 40 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC)) 41 .isEqualTo(ScreenLockType.PASSWORD); 42 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_BIOMETRIC_WEAK)) 43 .isNull(); 44 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_COMPLEX)) 45 .isEqualTo(ScreenLockType.PASSWORD); 46 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_MANAGED)) 47 .isEqualTo(ScreenLockType.MANAGED); 48 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC)) 49 .isEqualTo(ScreenLockType.PIN); 50 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX)) 51 .isEqualTo(ScreenLockType.PIN); 52 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING)) 53 .isEqualTo(ScreenLockType.PATTERN); 54 assertThat(ScreenLockType.fromQuality(DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED)) 55 .isEqualTo(ScreenLockType.SWIPE); 56 } 57 58 @Test 59 public void fromKey_shouldReturnLockWithGivenKey() { 60 for (ScreenLockType lock : ScreenLockType.values()) { 61 assertThat(ScreenLockType.fromKey(lock.preferenceKey)).isEqualTo(lock); 62 } 63 assertThat(ScreenLockType.fromKey("nonexistent")).isNull(); 64 } 65 } 66