1 /* 2 * Copyright (C) 2020 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.accessibility; 18 19 import static org.mockito.Mockito.spy; 20 import static org.mockito.Mockito.verify; 21 import static org.mockito.internal.verification.VerificationModeFactory.times; 22 23 import android.content.Context; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 27 import androidx.preference.PreferenceViewHolder; 28 29 import com.android.settings.R; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.robolectric.RobolectricTestRunner; 35 import org.robolectric.RuntimeEnvironment; 36 37 /** Tests for {@link DividerAllowedBelowPreference}. */ 38 @RunWith(RobolectricTestRunner.class) 39 public class DividerAllowedBelowPreferenceTest { 40 private final Context mContext = RuntimeEnvironment.application; 41 private PreferenceViewHolder mViewHolder; 42 43 @Before setUp()44 public void setUp() { 45 final LayoutInflater inflater = LayoutInflater.from(mContext); 46 final View rootView = 47 inflater.inflate(R.layout.preference, /* root= */ null); 48 mViewHolder = spy(PreferenceViewHolder.createInstanceForTests(rootView)); 49 } 50 51 @Test onBindViewHolder_dividerAllowedBelow()52 public void onBindViewHolder_dividerAllowedBelow() { 53 final DividerAllowedBelowPreference dividerAllowedBelowPreference = 54 new DividerAllowedBelowPreference(mContext); 55 56 dividerAllowedBelowPreference.onBindViewHolder(mViewHolder); 57 58 // One time was in parent, the other time was in child. 59 verify(mViewHolder, times(2)).setDividerAllowedBelow(true); 60 } 61 } 62