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.support.test.filters.SmallTest; 22 import android.support.test.filters.Suppress; 23 import android.test.AndroidTestCase; 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 { testComparator()38 public void testComparator() throws Exception { 39 final LinkedHashMap<String, Boolean> INPUT_ID_TO_PARTNER_INPUT = new LinkedHashMap<>(); 40 INPUT_ID_TO_PARTNER_INPUT.put("2_partner_input", true); 41 INPUT_ID_TO_PARTNER_INPUT.put("3_partner_input", true); 42 INPUT_ID_TO_PARTNER_INPUT.put("1_3rd_party_input", false); 43 INPUT_ID_TO_PARTNER_INPUT.put("4_3rd_party_input", false); 44 45 TvInputManagerHelper manager = Mockito.mock(TvInputManagerHelper.class); 46 Mockito.doAnswer(new Answer<Boolean>() { 47 @Override 48 public Boolean answer(InvocationOnMock invocation) throws Throwable { 49 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0]; 50 return INPUT_ID_TO_PARTNER_INPUT.get(info.getId()); 51 } 52 }).when(manager).isPartnerInput(Mockito.<TvInputInfo>any()); 53 Mockito.doAnswer(new Answer<String>() { 54 @Override 55 public String answer(InvocationOnMock invocation) throws Throwable { 56 TvInputInfo info = (TvInputInfo) invocation.getArguments()[0]; 57 return info.getId(); 58 } 59 }).when(manager).loadLabel(Mockito.<TvInputInfo>any()); 60 61 ComparatorTester<TvInputInfo> comparatorTester = 62 ComparatorTester.withoutEqualsTest( 63 new TvInputManagerHelper.TvInputInfoComparator(manager)); 64 ResolveInfo resolveInfo1 = TestUtils.createResolveInfo("1_test", "1_test"); 65 ResolveInfo resolveInfo2 = TestUtils.createResolveInfo("2_test", "2_test"); 66 for (String inputId : INPUT_ID_TO_PARTNER_INPUT.keySet()) { 67 TvInputInfo info1 = TestUtils.createTvInputInfo(resolveInfo1, inputId, null, 0, false); 68 TvInputInfo info2 = TestUtils.createTvInputInfo(resolveInfo2, inputId, null, 0, false); 69 comparatorTester.addComparableGroup(info1, info2); 70 } 71 comparatorTester.test(); 72 } 73 } 74