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