• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.tv.util;
18 
19 import android.content.pm.ResolveInfo;
20 import android.media.tv.TvInputInfo;
21 import android.test.AndroidTestCase;
22 import android.test.suitebuilder.annotation.SmallTest;
23 import android.test.suitebuilder.annotation.Suppress;
24 
25 import com.android.tv.testing.ComparatorTester;
26 
27 import org.mockito.Mockito;
28 import org.mockito.invocation.InvocationOnMock;
29 import org.mockito.stubbing.Answer;
30 
31 import java.util.LinkedHashMap;
32 
33 /**
34  * Test for {@link TvInputManagerHelper}
35  */
36 @SmallTest
37 public class TvInputManagerHelperTest extends AndroidTestCase {
38     @Suppress  // http://b/26903987
testComparator()39     public void testComparator() throws Exception {
40         final LinkedHashMap<String, Boolean> INPUT_ID_TO_PARTNER_INPUT = new LinkedHashMap<>();
41         INPUT_ID_TO_PARTNER_INPUT.put("2_partner_input", true);
42         INPUT_ID_TO_PARTNER_INPUT.put("3_partner_input", true);
43         INPUT_ID_TO_PARTNER_INPUT.put("1_3rd_party_input", false);
44         INPUT_ID_TO_PARTNER_INPUT.put("4_3rd_party_input", false);
45 
46         TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class);
47         Mockito.doAnswer(new Answer<Boolean>() {
48             @Override
49             public Boolean answer(InvocationOnMock invocation) throws Throwable {
50                 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
51                 return INPUT_ID_TO_PARTNER_INPUT.get(info.getId());
52             }
53         }).when(manager).isPartnerInput(Mockito.<TvInputInfo>any());
54         Mockito.doAnswer(new Answer<String>() {
55             @Override
56             public String answer(InvocationOnMock invocation) throws Throwable {
57                 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0];
58                 return info.getId();
59             }
60         }).when(manager).loadLabel(Mockito.<TvInputInfo>any());
61 
62         ComparatorTester<TvInputInfo> comparatorTester =
63                 ComparatorTester.withoutEqualsTest(
64                         new TvInputManagerHelper.TvInputInfoComparator(manager));
65         ResolveInfo resolveInfo1 = TestUtils.createResolveInfo("1_test", "1_test");
66         ResolveInfo resolveInfo2 = TestUtils.createResolveInfo("2_test", "2_test");
67         for (String inputId : INPUT_ID_TO_PARTNER_INPUT.keySet()) {
68             TvInputInfo info1 = TestUtils.createTvInputInfo(resolveInfo1, inputId, null, 0, false);
69             TvInputInfo info2 = TestUtils.createTvInputInfo(resolveInfo2, inputId, null, 0, false);
70             comparatorTester.addComparableGroup(info1, info2);
71         }
72         comparatorTester.test();
73     }
74 }
75