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.panel;
18 
19 import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import static org.mockito.Mockito.spy;
24 import static org.mockito.Mockito.when;
25 
26 import android.content.Context;
27 import android.net.Uri;
28 
29 import com.android.settings.slices.CustomSliceRegistry;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.MockitoAnnotations;
35 import org.robolectric.RobolectricTestRunner;
36 import org.robolectric.RuntimeEnvironment;
37 
38 import java.util.List;
39 
40 @RunWith(RobolectricTestRunner.class)
41 public class MediaOutputGroupPanelTest {
42 
43     private static final String TEST_PACKAGENAME = "com.test.packagename";
44 
45     private MediaOutputGroupPanel mPanel;
46     private Context mContext;
47 
48     @Before
setUp()49     public void setUp() {
50         MockitoAnnotations.initMocks(this);
51 
52         mContext = spy(RuntimeEnvironment.application);
53         when(mContext.getApplicationContext()).thenReturn(mContext);
54         mPanel = MediaOutputGroupPanel.create(mContext, TEST_PACKAGENAME);
55     }
56 
57     @Test
getSlices_containsNecessarySlices()58     public void getSlices_containsNecessarySlices() {
59         final List<Uri> uris = mPanel.getSlices();
60 
61         assertThat(uris).containsExactly(CustomSliceRegistry.MEDIA_OUTPUT_GROUP_SLICE_URI);
62     }
63 
64     @Test
getSlices_verifyPackageName_isEqual()65     public void getSlices_verifyPackageName_isEqual() {
66         final List<Uri> uris = mPanel.getSlices();
67 
68         assertThat(uris.get(0).getQueryParameter(MEDIA_PACKAGE_NAME)).isEqualTo(TEST_PACKAGENAME);
69     }
70 
71     @Test
getSeeMoreIntent_isNull()72     public void getSeeMoreIntent_isNull() {
73         assertThat(mPanel.getSeeMoreIntent()).isNull();
74     }
75 
76     @Test
getViewType_checkType()77     public void getViewType_checkType() {
78         assertThat(mPanel.getViewType()).isEqualTo(PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
79     }
80 }
81