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 package com.android.settings.widget;
17 
18 import static org.mockito.Mockito.spy;
19 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.when;
21 
22 import android.content.Context;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.widget.LinearLayout;
26 import android.widget.TextView;
27 
28 import androidx.preference.PreferenceViewHolder;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.robolectric.RobolectricTestRunner;
36 import org.robolectric.RuntimeEnvironment;
37 
38 @RunWith(RobolectricTestRunner.class)
39 public class FixedLineSummaryPreferenceTest {
40 
41     @Mock
42     private TextView mSummary;
43 
44     private Context mContext;
45     private PreferenceViewHolder mHolder;
46     private FixedLineSummaryPreference mPreference;
47 
48     @Before
setUp()49     public void setUp() {
50         MockitoAnnotations.initMocks(this);
51 
52         mContext = RuntimeEnvironment.application;
53         mPreference = new FixedLineSummaryPreference(mContext, null);
54         LayoutInflater inflater = LayoutInflater.from(mContext);
55         final View view =
56             inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
57         mHolder = spy(PreferenceViewHolder.createInstanceForTests(view));
58         when(mHolder.findViewById(android.R.id.summary)).thenReturn(mSummary);
59     }
60 
61     @Test
onBindViewHolder_shouldSetSingleLine()62     public void onBindViewHolder_shouldSetSingleLine() {
63         mPreference.onBindViewHolder(mHolder);
64 
65         verify(mSummary).setMinLines(1);
66         verify(mSummary).setMaxLines(1);
67     }
68 
69     @Test
onBindViewHolder_TwoLineSummary_shouldSetTwoLines()70     public void onBindViewHolder_TwoLineSummary_shouldSetTwoLines() {
71         mPreference.setSummaryLineCount(2);
72         mPreference.onBindViewHolder(mHolder);
73 
74         verify(mSummary).setMinLines(2);
75         verify(mSummary).setMaxLines(2);
76     }
77 }
78