1 /*
2  * Copyright (C) 2024 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.ArgumentMatchers.any;
20 import static org.mockito.Mockito.doReturn;
21 import static org.mockito.Mockito.verify;
22 
23 import android.content.Context;
24 import android.view.View;
25 import android.widget.LinearLayout;
26 
27 import androidx.preference.PreferenceViewHolder;
28 import androidx.test.core.app.ApplicationProvider;
29 
30 import com.android.settings.R;
31 
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Spy;
37 import org.mockito.junit.MockitoJUnit;
38 import org.mockito.junit.MockitoRule;
39 import org.robolectric.RobolectricTestRunner;
40 
41 /** Tests for {@link BackgroundPreference} */
42 @RunWith(RobolectricTestRunner.class)
43 public class BackgroundPreferenceTest {
44 
45     @Rule
46     public final MockitoRule mMockitoRule = MockitoJUnit.rule();
47 
48     private final Context mContext = ApplicationProvider.getApplicationContext();
49 
50     private View mRootView = new View(mContext);
51     @Spy
52     private PreferenceViewHolder mViewHolder = PreferenceViewHolder.createInstanceForTests(
53             mRootView);
54     @Spy
55     private LinearLayout mLinearLayout = new LinearLayout(mContext);
56     private BackgroundPreference mPreference;
57 
58     @Before
setUp()59     public void setUp() {
60         mPreference = new BackgroundPreference(mContext);
61     }
62 
63     @Test
setBackground_success()64     public void setBackground_success() {
65         doReturn(mLinearLayout).when(mViewHolder).findViewById(R.id.background);
66 
67         mPreference.setBackground(android.R.drawable.screen_background_dark);
68         mPreference.onBindViewHolder(mViewHolder);
69 
70         verify(mLinearLayout).setBackground(any());
71     }
72 }
73