• 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.fingerprint;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.verify;
21 
22 import android.content.Context;
23 import android.support.v7.preference.PreferenceViewHolder;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.widget.FrameLayout;
27 
28 import com.android.settings.R;
29 import com.android.settings.fingerprint.FingerprintSettings.FingerprintPreference;
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 import org.robolectric.RuntimeEnvironment;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 public class FingerprintPreferenceTest {
41 
42     @Mock
43     private FingerprintPreference.OnDeleteClickListener mOnDeleteClickListener;
44 
45     private Context mContext;
46     private FingerprintPreference mPreference;
47 
48     @Before
setUp()49     public void setUp() {
50         MockitoAnnotations.initMocks(this);
51         mContext = RuntimeEnvironment.application;
52         mPreference = new FingerprintPreference(mContext, mOnDeleteClickListener);
53     }
54 
55     @Test
shouldShowDeleteButton()56     public void shouldShowDeleteButton() {
57         assertThat(mPreference.getSecondTargetResId()).isEqualTo(R.layout.preference_widget_delete);
58     }
59 
60     @Test
bindAndClickDeleteButton_shouldInvokeOnDeleteListener()61     public void bindAndClickDeleteButton_shouldInvokeOnDeleteListener() {
62         final FrameLayout layout = new FrameLayout(mContext);
63         LayoutInflater.from(mContext).inflate(mPreference.getSecondTargetResId(), layout, true);
64         final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(layout);
65         mPreference.onBindViewHolder(holder);
66 
67         final View view = layout.findViewById(R.id.delete_button);
68         assertThat(view).isNotNull();
69         view.performClick();
70 
71         verify(mOnDeleteClickListener).onDeleteClick(mPreference);
72     }
73 }
74