Home | History | Annotate | Download | only in fingerprint
      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.fingerprint;
     18 
     19 import static com.google.common.truth.Truth.assertThat;
     20 import static org.mockito.Matchers.any;
     21 import static org.mockito.Matchers.anyInt;
     22 import static org.mockito.Matchers.eq;
     23 import static org.mockito.Mockito.when;
     24 
     25 import android.app.admin.DevicePolicyManager;
     26 import android.content.Context;
     27 import android.content.pm.PackageManager;
     28 import android.hardware.fingerprint.FingerprintManager;
     29 
     30 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     31 
     32 import org.junit.Before;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 import org.mockito.Mock;
     36 import org.mockito.MockitoAnnotations;
     37 
     38 @RunWith(SettingsRobolectricTestRunner.class)
     39 public class FingerprintEnrollSuggestionActivityTest {
     40 
     41     @Mock
     42     private Context mContext;
     43     @Mock
     44     private PackageManager mPackageManager;
     45     @Mock
     46     private FingerprintManager mFingerprintManager;
     47     @Mock
     48     private DevicePolicyManager mDevicePolicyManager;
     49 
     50     @Before
     51     public void setUp() {
     52         MockitoAnnotations.initMocks(this);
     53         when(mContext.getPackageManager()).thenReturn(mPackageManager);
     54         when(mContext.getSystemService(eq(Context.DEVICE_POLICY_SERVICE)))
     55                 .thenReturn(mDevicePolicyManager);
     56         when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt())).thenReturn(0);
     57         when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
     58                 .thenReturn(mFingerprintManager);
     59     }
     60 
     61     @Test
     62     public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintAdded() {
     63         stubFingerprintSupported(true);
     64         when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
     65         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
     66 
     67         assertThat(FingerprintEnrollSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
     68     }
     69 
     70     @Test
     71     public void testFingerprintEnrollmentIntroductionIsNotCompleteWhenNoFingerprintAdded() {
     72         stubFingerprintSupported(true);
     73         when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
     74         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
     75 
     76         assertThat(FingerprintEnrollSuggestionActivity.isSuggestionComplete(mContext)).isFalse();
     77     }
     78 
     79     @Test
     80     public void testFingerprintEnrollmentIntroductionIsCompleteWhenHardwareNotDetected() {
     81         stubFingerprintSupported(true);
     82         when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
     83         when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
     84 
     85         assertThat(FingerprintEnrollSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
     86     }
     87 
     88     @Test
     89     public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintNotSupported() {
     90         stubFingerprintSupported(false);
     91 
     92         assertThat(FingerprintEnrollSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
     93     }
     94 
     95     @Test
     96     public void testFingerprintEnrollmentIntroductionIsCompleteWhenFingerprintDisabled() {
     97         stubFingerprintSupported(true);
     98         when(mFingerprintManager.hasEnrolledFingerprints()).thenReturn(false);
     99         when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
    100         when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
    101                 .thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT);
    102 
    103         assertThat(FingerprintEnrollSuggestionActivity.isSuggestionComplete(mContext)).isTrue();
    104     }
    105 
    106     private void stubFingerprintSupported(boolean enabled) {
    107         when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
    108                 .thenReturn(enabled);
    109     }
    110 }
    111